Jump to content
xStingEucliffexxx

How to open a .pas file and position the line?

Recommended Posts

Hello Guys,

 

How to open a .pas file in Delphi and position the desired line of code, example: open the file and go to line 207 of the unit

I saw some topics about ToolsAPI, using IOTA
but I couldn't understand much,
Has anyone managed to perform this magic?

Share this post


Link to post

Yes, you are going to use IOTA but you really need to read up on this topic until you understand it.

 

The basic steps you must take is something like this (pseudo code; don't try to compile it):

// Open the file in the IDE
(BorlandIDEServices as IOTAActionServices).OpenFile('my_unit.pas');

// Get the file "module"
var Module: IOTAModule := (BorlandIDEServices as IOTAModuleServices).FindModule('my_unit.pas');

// Iterate the module files
for var i := 0 to Module.GetModuleFileCount-1 do
begin

// Get a module file editor
  var Editor: IOTASourceEditor;
  if not Supports(Module.GetModuleFileEditor(i), IOTASourceEditor, Editor) then
    continue;

  // Make the editor visible
  Editor.Show

  // Get an editor view
  if (Editor.GetEditViewCount = 0) then
    continue;
  var EditView: IOTAEditView := Editor.GetEditView(0);
  
  // Set the caret position
  var Position: TOTAEditPos;
  Position.Col := 1;
  Position.Line := ...
  EditView.SetCursorPos(Position);
  
  // Scroll to make caret visible and 15 lines down from the top
  Position.Line := Max(1, Position.Line-15);
  SetView.SetTopPos(Position);
end;
  • Like 3

Share this post


Link to post
On 4/19/2024 at 5:53 AM, Anders Melander said:

Sim, você vai usar IOTA, mas você realmente precisa ler sobre este tópico até que você entenda.

 

Os passos básicos que você deve tomar é algo como este (pseudo código; não tente compilá-lo):


// Open the file in the IDE
(BorlandIDEServices as IOTAActionServices).OpenFile('my_unit.pas');

// Get the file "module"
var Module: IOTAModule := (BorlandIDEServices as IOTAModuleServices).FindModule('my_unit.pas');

// Iterate the module files
for var i := 0 to Module.GetModuleFileCount-1 do
begin

// Get a module file editor
  var Editor: IOTASourceEditor;
  if not Supports(Module.GetModuleFileEditor(i), IOTASourceEditor, Editor) then
    continue;

  // Make the editor visible
  Editor.Show

  // Get an editor view
  if (Editor.GetEditViewCount = 0) then
    continue;
  var EditView: IOTAEditView := Editor.GetEditView(0);
  
  // Set the caret position
  var Position: TOTAEditPos;
  Position.Col := 1;
  Position.Line := ...
  EditView.SetCursorPos(Position);
  
  // Scroll to make caret visible and 15 lines down from the top
  Position.Line := Max(1, Position.Line-15);
  SetView.SetTopPos(Position);
end;

 


Thanks man, I'll analyze it and see in practice, I'll give you feedback if I achieved something

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

×