Delphi中如何通过ToolsAPI获取模块的结构?

发布于 2024-09-06 09:50:35 字数 121 浏览 1 评论 0原文

我想通过ToolsAPI获取模块(pascal单元)的结构信息。就像 IDE 的结构视图一样。

类、记录、接口、变量/常量等 成员、参数等

是否已经有一个简单的&获取这些元数据的有效方法?

I want to get the structure information of a module (pascal unit) by ToolsAPI. just like the structure view of the IDE does.

Classes, Records, Interfaces, Variables/Constants, etc
Members, Parameters, etc.

Is there already an easy & efficient way to get these metadata?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

糖果控 2024-09-13 09:50:35

AFAIK 没有办法查询给定文件的特殊结构化信息。

您可以做的是访问“结构”窗格中的信息。这种方式要求文件是活动模块(可以通过 OTA 实现),输出取决于结构窗格设置(工具 | 选项... -> 环境选项 | 资源管理器),并且如果节点是字段,一个过程或任何需要通过图像索引、父级确定的内容...

此代码遍历“结构”窗格。

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;

AFAIK there is no way to query special structured information for a given file.

What you could do is to access the information in the Structure pane. That way requires the file to be the active module (can be achieved by the OTA), the output depends on the Structure pane settings (Tools | Options... -> Environment Options | Explorer) and if a node is a field, a procedure or whatever needs to be determined over the image index, parent...

This code walks through the Structure pane.

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;
沉默的熊 2024-09-13 09:50:35

也许使用解析器并不是一个坏主意?

Maybe using a parser is not so bad idea?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文