2

我正在为这个问题做一些跑腿工作,特别是对于以下句子:

我什至无法从 IOTAProject 获得这个接口。

我再次指的是 Erik Berry 概述的Delphi 2005 和 2006 中存在的众所周知的缺陷。请访问链接的 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}不再有效的语法
4

1 回答 1

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);

但无论如何我一直没有找到!!!信息。

于 2013-12-29T17:22:11.790 回答