delphi - 我可以通过什么方式生成项目中使用的 DFM 列表?

标签 delphi linker

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

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

如果列出了所有 DFM,则可以提取有关该项目的信息,并且可能仅对当前项目 DFM 进行搜索,例如解析 DFM 以查找属性。

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

最佳答案

这是一个使用 OpenTools API 的快速示例。将此单元添加到新的仅设计包中,并将 designidevcl 添加到 requires 子句中。编译并安装该包。它将在 Help\Help Wizards 下添加一个菜单项“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.

关于delphi - 我可以通过什么方式生成项目中使用的 DFM 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45718587/

相关文章:

linux - 链接到静态库后 undefined reference

delphi - TAction.OnExecute 未执行

c++ - 链表输出不正确(c++)

c++ - 链接/集成问题。我需要去哪里的方向?

Delphi HMAC-SHA1 意想不到的结果

linker - 如何将文本文件的内容添加为 ELF 文件中的一个部分?

c++ - cmake - 全局链接器标志设置(针对目录中的所有目标)

database - 有没有办法自动删除文本字段中的所有前导和尾随空格

windows - 如何为未注册的文件扩展名显示 "open with"对话框?

delphi - TWebBrowser 如何在 IE8 上将插入符位置设置为 INPUT(text) 字段的末尾