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 に答える