我想做一个Delphi插件,可以列出当前项目中的所有DFM。
有没有办法获取当前项目中链接的所有 DFM 文件(及其路径)的列表?
如果列出了所有 DFM,则可以提取有关该项目的信息,并且可能仅对当前项目 DFM 进行搜索,例如解析 DFM 以查找属性。
我确实找到了this question ,已回答,但没有解决如何到达 DFM。该解决方案需要更改存储库中的每个 .pas 文件,并在运行时提供解决方案。我的问题是关于设计时的。
最佳答案
这是一个使用 OpenTools API 的快速示例。将此单元添加到新的仅设计包中,并将 designide
和 vcl
添加到 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/