Jump to content
domus

Way for external app to jump to a unit and position inside the IDE?

Recommended Posts

Would anyone know of a way for an external app to jump to a certain unit and position inside the IDE? Like, unit "Main.pas", line 100.

 

Many thanks for pointers.

Share this post


Link to post

You can use

  ShellExecute(0, 'open', PChar(FileName), nil, nil, SW_SHOWNORMAL);

to show the unit in your registered Pascal editor - which probably is Delphi.

I don't know about the line number.

  • Like 1

Share this post


Link to post

That's indeed a way to get me started. Totally forgot about ShellExecute being an option here. Thanks for that!

 

If anyone would know of a way to navigate to a certain procedure or class, or line number, I'd be grateful to receive that knowledge. But it's probably all documented somewhere in the Tools API documentation and I should just resort to reading it.

Share this post


Link to post
1 hour ago, domus said:

Would anyone know of a way for an external app to jump to a certain unit and position inside the IDE? Like, unit "Main.pas", line 100.

 

Many thanks for pointers.

AFAIK this can only be done using the OTAPI which is only available for IDE plugins.

Edited by dummzeuch
  • Like 1

Share this post


Link to post
35 minutes ago, dummzeuch said:

AFAIK this can only be done using the OTAPI which ins only available for IDE plugins.

That's the problem. I'd need to write a plugin that listens to the external app...

 

Thanks and cheers.

Share this post


Link to post

To open a file you can use DDE, which @Attila Kovacs got working some time ago:

As for repositioning, you can try to get the handle of the editor control and send a EM_SETSEL message.


That would be my approach, that is.

 

  • Like 1

Share this post


Link to post
54 minutes ago, aehimself said:

That would be my approach, that is.

Excellent approach. I'll give it a try. Thanks!

Share this post


Link to post
6 hours ago, aehimself said:

As for repositioning, you can try to get the handle of the editor control and send a EM_SETSEL message.

I don't think this will work as the editor control (TEditControl) does not descend from TEdit or TMemo but from TWinControl (via TCustomControl -> TCustomEditControl):

IdeEditor.thumb.png.094ffa0c40e6acfb10a0016bd70cb51b.png

 

But I might be wrong, maybe one of those controls processes this message.

 

Edit: TMemo descends from TCustomEdit (which itself descends from TWinControl), not from TCustomEditControl.

Edited by dummzeuch
  • Like 1

Share this post


Link to post

That's a pity. Unfortunately the source of TEditControl and TCustomEditControl is buried somewhere so we can not be sure what it can do, what it will reply to.

Worths a try though, maybe...

Share this post


Link to post

I wonder where @RRUZ got this unit. IF we are talking about the same component, according to it, TEditControl has two published properties:

property CaretX: SmallInt;
property CaretY: Integer;

If we can find out how to access this type from a Delphi application (even without source) I'm sure TEditControl could be accessed via it's handle and some pointer magic...

  • Like 1

Share this post


Link to post

If you're prepared to write a wizard you might find something in this fragments from a very old wizard I no longer use:

procedure TMyWizMainForm.ShowInMessageView(const FileName, MessageStr: string;
  LineNumber, ColumnNumber: Integer);
var
  MessageServices: IOTAMessageServices40;
begin
  MessageServices := BorlandIDEServices as IOTAMessageServices40;
  MessageServices.ClearCompilerMessages;
  MessageServices.ClearToolMessages;
  MessageServices.AddToolMessage(FileName, MessageStr, '.....', LineNumber, ColumnNumber);
  ShowMessageView;
end;

procedure TMyWizMainForm.ShowUnitSource(const FileName: string);
begin
  (BorlandIDEServices as IOTAActionServices).OpenFile(FileName);
end;

procedure TMyWizMainForm.ShowParseError(e: EParseError);
var
  EditorServices: IOTAEditorServices;
  TopView: IOTAEditView;
  EditActions: IOTAEditActions;
begin
  ShowInMessageView(CurrUnit, e.Message, e.LineNo, e.ColumnNo);
  EditorServices := BorlandIDEServices as IOTAEditorServices;
  TopView := EditorServices.TopView;
  if TopView = nil then
  begin
    ShowUnitSource(CurrUnit);
    TopView := EditorServices.TopView;
  end;
  if TopView <> nil then
  begin
    EditActions := TopView as IOTAEditActions;
    EditActions.NextError;
  end;

  Close;
  Beep;
end;

It works (worked?) by inserting a custom line into the IDE's message window and make the IDE jump there.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×