How to get module structure using ToolsAPI in Delphi?

I want to get information about the structure of the module (Pascal block) using ToolsAPI. as well as representing the IDE structure.

Classes, records, interfaces, variables / constants, etc. Members, parameters, etc.

Is there an easy and efficient way to get this metadata?

+3
source share
2 answers

Maybe using parser is not such a bad idea?

+2
source

AFAIK there is no way to request specific structured information for a given file.

, "". , ( OTA), (Tools | Options... → Environment Options | Explorer), node , - , ...

"".

procedure StructureViewToSL(ASL: TStringList);

  procedure TreeToSL(ANode: IOTAStructureNode; ASL: TStringList; const APrefix: string);
  var
    I: Integer;
  begin
    ASL.Add(APrefix + ANode.Caption);
    for I := 0 to ANode.ChildCount - 1 do
      TreeToSL(ANode.Child[I], ASL, APrefix + '  ');
  end;

var
  StructureView: IOTAStructureView;
  StructureContext: IOTAStructureContext;
  Node: IOTAStructureNode;
  I: Integer;
begin
  StructureView := BorlandIDEServices as IOTAStructureView;
  StructureContext := StructureView.GetStructureContext;
  for I := 0 to StructureContext.RootNodeCount - 1 do
  begin
    Node := StructureContext.GetRootStructureNode(I);
    TreeToSL(Node, ASL, '');
  end;
end;
+4

Source: https://habr.com/ru/post/1750778/


All Articles