Delphi 我可以用什么方式生成项目中使用的DFM列表?

Delphi 我可以用什么方式生成项目中使用的DFM列表?,delphi,linker,Delphi,Linker,我想做一个Delphi插件,它可以列出当前项目中的所有DFM 是否有方法获取当前项目中链接的所有DFM文件(及其路径)的列表 如果列出了所有DFM,那么就可以提取项目的相关信息,并且可能只对当前项目DFM进行搜索,比如解析DFM以查找属性 我确实找到了答案,但没有说明如何到达DFMs。该解决方案需要更改存储库中的每个.pas文件,并在运行时提供解决方案。我的问题是关于设计时间。这里有一个使用OpenTools API的快速示例。将此装置添加到新的纯设计包中,将designide和vcl添加到re

我想做一个Delphi插件,它可以列出当前项目中的所有DFM

是否有方法获取当前项目中链接的所有DFM文件(及其路径)的列表

如果列出了所有DFM,那么就可以提取项目的相关信息,并且可能只对当前项目DFM进行搜索,比如解析DFM以查找属性


我确实找到了答案,但没有说明如何到达DFMs。该解决方案需要更改存储库中的每个
.pas
文件,并在运行时提供解决方案。我的问题是关于设计时间。

这里有一个使用OpenTools API的快速示例。将此装置添加到新的纯设计包中,将
designide
vcl
添加到
requires
子句中。编译并安装软件包。它将在Help\Help向导下添加一个菜单项“List DFM”。单击它将调用下面的
Execute
方法

unit ListDfmExample;

interface

uses
  Windows, VCL.Forms, VCL.Dialogs, Classes, SysUtils, ToolsAPI;

type
  TListDfmWizard = class(TNotifierObject, IOTAWizard, IOTAMenuWizard)
    { IOTAWizard }
    function GetIDString: string;
    function GetName: string;
    function GetState: TWizardState;
    procedure Execute;
    { IOTAMenuWizard }
    function GetMenuText: string;
  end;

implementation

function TListDfmWizard.GetIDString: string;
begin
  Result := 'TOndrej.ListDfmWizard';
end;

function TListDfmWizard.GetName: string;
begin
  Result := 'ListDfm';
end;

function TListDfmWizard.GetState: TWizardState;
begin
  Result := [wsEnabled];
end;

procedure TListDfmWizard.Execute;
var
  Project: IOTAProject;
  I, J: Integer;
  ModuleInfo: IOTAModuleInfo;
  Module: IOTAModule;
  Editor: IOTAEditor;
  FormEditor: IOTAFormEditor;
  List: TStringList;
begin
  Project := GetActiveProject;
  if not Assigned(Project) then
    Exit;

  List := TStringList.Create;
  try
    for I := 0 to Project.GetModuleCount - 1 do
    begin
      ModuleInfo := Project.GetModule(I);
      if ModuleInfo.FormName <> '' then
      begin
        Module := ModuleInfo.OpenModule;
        for J := 0 to Module.ModuleFileCount - 1 do
        begin
          Editor := Module.ModuleFileEditors[J];
          if Supports(Editor, IOTAFormEditor, FormEditor) then
            List.Add(FormEditor.FileName);
        end;
      end;
    end;

    ShowMessage(List.Text);
  finally
    List.Free;
  end;
end;

function TListDfmWizard.GetMenuText: string;
begin
  Result := 'List DFM';
end;

initialization
  RegisterPackageWizard(TListDfmWizard.Create);

end.
unitlistdfme示例;
接口
使用
Windows、VCL.Forms、VCL.Dialogs、类、SysUtils、ToolsAPI;
类型
TListDfmWizard=class(TNotifierObject、IOTAWizard、IOTAMenuWizard)
{IOTAWizard}
函数GetIDString:string;
函数GetName:string;
函数GetState:TWizardState;
程序执行;
{IOTAMenuWizard}
函数GetMenuText:string;
结束;
实施
函数TListDfmWizard.GetIDString:string;
开始
结果:=“TOndrej.ListDfmWizard”;
结束;
函数TListDfmWizard.GetName:string;
开始
结果:='ListDfm';
结束;
函数TListDfmWizard.GetState:TWizardState;
开始
结果:=[wsEnabled];
结束;
过程TListDfmWizard.Execute;
变量
项目:物联网项目;
一、 J:整数;
ModuleInfo:IOTAModuleInfo;
模块:物联网模块;
编辑:IOTAEditor;
表单编辑器:IOTAFormEditor;
列表:TStringList;
开始
项目:=GetActiveProject;
如果未分配(项目),则
出口
列表:=TStringList.Create;
尝试
对于I:=0到Project.GetModuleCount-1 do
开始
ModuleInfo:=Project.GetModule(I);
如果ModuleInfo.FormName为“”,则
开始
模块:=ModuleInfo.OpenModule;
对于J:=0到Module.ModuleFileCount-1 do
开始
编辑器:=Module.moduleFileEditor[J];
如果支持(编辑器、IOTAFormEditor、FormEditor),则
添加(FormEditor.FileName);
结束;
结束;
结束;
ShowMessage(List.Text);
最后
列表。免费;
结束;
结束;
函数TListDfmWizard.GetMenuText:string;
开始
结果:='列出DFM';
结束;
初始化
RegisterPackageWizard(TListDfmWizard.Create);
结束。

您说的是插件,所以我假设您希望在设计时找到表单?请澄清..IDE插件是使用实现的,它具有用于枚举项目设置、表单、关联文件(
.pas
.dfm
)等的接口。请查看
工具SAPI
和相关单元,以及
IoTapProject组
IOTAProject
IOTAModule
接口(仅举几个例子),以及
GetActiveProject()
独立函数。如果你环顾四周,就会发现很多OpenTools教程。是的,我想在设计时找到表单。是的,我正在使用IOTA。然而,我刚刚找到了如何创建项目,却找不到关于如何迭代数据的教程。一本关于这个主题的书。这个代码只适用于小规模的项目。如果一个项目有超过100个表单,它可能会出现错误“创建表单系统错误代码1158”是否缺少某些内容?