我正在为this question做一些练习,特别是对于以下句子:
我甚至无法从IOTAProject获得此接口。
再次 我指的是Delphi 2005和2006 outlined by Erik Berry中存在的众所周知的缺陷。请访问链接的QC条目以获取完整的测试用例。
够了,这是我的代码:
procedure TResDumpWizard.Execute;
var
Project: IOTAProject;
Resource: IOTAProjectResource;
I: Integer;
Entry: IOTAResourceEntry;
begin
Project := (BorlandIDEServices as IOTAModuleServices).GetActiveProject;
Assert(Assigned(Project), 'No active project');
Resource := nil;
for I := 0 to Project.ModuleFileCount - 1 do
begin
if Supports(Project.ModuleFileEditors[I], IOTAProjectResource, Resource) then
Break;
end;
Assert(Assigned(Resource), 'No resources in project'); // (!!!) always fails
for I := 0 to Resource.GetEntryCount - 1 do
begin
Entry := Resource.GetEntry(I);
(BorlandIDEServices as IOTAMessageServices).AddTitleMessage(DisplayName(Entry.GetResourceName));
end;
end;
循环项目的模块文件编辑器永远不会找到任何资源,即使项目有其他资源
{$RESOURCE binary.res}
指令{$R filename.res filename.rc}
语法答案 0 :(得分:0)
(我的声誉很低,所以无法添加评论)
Project.ModuleFileCount始终返回1,Project.ModuleFileEditors [0] .FileName返回ProjectName.dpr
在我测试的XE3中,可以使用以下代码枚举项目的所有模块:
var i, j: Integer;
Resource: IOTAProjectResource;
ModuleInfo: IOTAModuleInfo;
Module: IOTAModule;
Editor: IOTAEditor;
Resource := nil;
for i := 0 to Project.GetModuleCount - 1 do
begin
ModuleInfo := Project.GetModule(i);
try
Module := ModuleInfo.OpenModule; // can raise exception
for j := 0 to Module.ModuleFileCount - 1 do
begin
Editor := Module.ModuleFileEditors[j];
if Supports(Editor, IOTAProjectResource, Resource) then
Break;
end;
except
end;
if Assigned(Resource) then Break;
end;
if not Assigned(Resource) then
MessageBox(0, 'Not found!!!', 'Info', 0);
但无论如何我总是找不到!!!消息。