【问题标题】:Is IOTAProjectResource broken (again!) in Delphi XE2 (and probalbly XE3 too)?IOTAProjectResource 是否在 Delphi XE2(也可能是 XE3)中损坏(再次!)?
【发布时间】:2013-12-29 09:51:59
【问题描述】:

我正在为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} 语法不再有效

【问题讨论】:

    标签: delphi delphi-xe2 toolsapi


    【解决方案1】:

    (我的声誉很低,所以无法添加评论)

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

    但无论如何我始终没有找到!!!消息。

    【讨论】:

    • 您没有足够的代表发表评论这一事实并不是写不回答的理由。这以何种方式回答了所提出的问题?
    • 我认为主题启动器使用了错误的模块枚举算法。
    • 我不能说你的技术有什么问题,但打开每个拥有的模块对我来说似乎有点过分了。无论如何,问题中演示的为项目(==所有者模块)定位IOTAProjectResource编辑器的方法在Delphi 2007中有效,Project.GetModuleFileCount返回2(同样,GetModuleFileEditor(1).FileName指向.RES文件)。
    猜你喜欢
    • 2012-03-07
    • 2012-12-08
    • 1970-01-01
    • 2011-12-25
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    相关资源
    最近更新 更多