c++delphitoolsapi

Insert text at cursor position in Embarcadero Tools API


I'm writing an extension for the Embarcadero C++ Builder IDE and want to programmatically insert text inside the code editor at the cursor position. I searched the Tools API header files but only found an interface which allows me to insert text at the start of the editor.

Is there any interface or function which allows me to insert text at a specified position? And if so, can you provide me a code example?

I'm writing the extension in C++, but code examples in Delphi will do too.


Solution

  • From this document by Bruno Fierens, Extending the Delphi IDE:

    var
      EditorServices: IOTAEditorServices;
      EditView: IOTAEditView;
      copyright: string;
    begin
      copyright := '{ Copyright © 2011 by tmssoftware.com }';
      EditorServices := BorlandIDEServices as IOTAEditorServices;
    
      EditView := EditorServices.TopView;
    
      if Assigned(EditView) then
      begin
        // position cursor at 1,1
        EditView.Buffer.EditPosition.Move(1,1);
        // insert copyright notice on top
        EditView.Buffer.EditPosition.InsertText(copyright);
      end;
    end;
    

    Using EditView.Buffer.EditPosition.Move() you should be able to freely move the cursor to any location.