-2

What is a new way to get current file that is being worked on in Experts for Delphi XE

Previously in Delphi 5-7 we used ToolServices.getCurrentFile

Irfan Mulic
  • 1,186
  • 3
  • 14
  • 28
  • 3
    You'll have to show us more than that. – David Heffernan Oct 06 '11 at 17:15
  • 4
    -1. So, this is an expert *you've* written, or just one you've gotten from somewhere else? *How* does it fail? You fix it by finding the bug and fixing it. – Rob Kennedy Oct 06 '11 at 17:50
  • I have edited the post. Problem is with broken interface introduced in Delphi XE but I can not find a solution for it yet. I can reformulate the question by asking how to get the current file I am working on in Delphi tools Api. – Irfan Mulic Oct 06 '11 at 18:05
  • Still -1. Everything in my previous comment still applies. – Rob Kennedy Oct 06 '11 at 18:14
  • Ok, I am working on it. ToolServices is a reference in deprecated unit that exposes the IDE. Simply it is not initialized by delphi when expert is loaded. I have to find another way of getting current file being worked on in editor. – Irfan Mulic Oct 06 '11 at 18:19
  • -1 for a bad question, and then failing to answer any requests for additional info when people are trying to help anyway. If you want help, provide information. "My something doesn't work. What's wrong?" is very hard to provide a solution for, especially when you haven't defined "something" or "doesn't work". "It used to work, now it doesn't" isn't helpful either. When people ask for more information in comments, give them that information - you're the one who wants help solving the problem. – Ken White Oct 07 '11 at 01:49
  • @Irfan The problem was that the question lacked detail. In fact the edits have made it worse. You obviously knew about some deprecation that we did not necessarily know about. That would have been good to describe. – David Heffernan Oct 07 '11 at 10:30

2 Answers2

6

Perhaps the deprecated units ToolIntf, ExptIntf etc. are no longer working. You can use IOTAModuleServices.CurrentModule instead. Here's a quick example:

function GetCurrentEditorFileName: string;
var
  Module: IOTAModule;
  Editor: IOTAEditor;
begin
  Result := '';
  Module := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
  if Assigned(Module) then
  begin
    Editor := Module.CurrentEditor;
    if Assigned(Editor) then
      Result := Editor.FileName;
  end;
end;
Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • and is more helpful to try to investigate a little bit the problem before you hit the -1! +1 TOndrej for the right answer. – RBA Oct 06 '11 at 20:42
  • Thanks RBA, I thought it was reasonable question. – Irfan Mulic Oct 06 '11 at 21:39
  • 1
    @RBA: It's more helpful for the OP to read the comments, and provide the information asked for in them. If there's no information in the question, it's much harder to answer. If you want help, provide what people need to help you when they ask - if they have to guess, it's much more work (and help here is **free**, remember?). "I get errors" or "it doesn't work" gives no one anything to use to help. If you get errors, say *exactly* what the error is; without that info, we're blind. +1 to TOndrej for psychic debugging skills, though. :) – Ken White Oct 07 '11 at 01:46
0

An alternate method is to pass the "name of file in the editor" to your tool as a parameter. $EDNAME

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
  • This might work for a wizard, but not for an expert. Experts typically run in the IDE (as packages), and therefore don't get command line params; wizards can be external executables and can get the params. – Ken White Oct 07 '11 at 02:01