2

I was doing some legwork for this question, specifically, for the following sentence:

I even could not get this interface from IOTAProject.

By again I mean well-known defect present in Delphi 2005 and 2006 outlined by Erik Berry. Please visit linked QC entry for complete testcase.

Enough words, here is the my code:

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;

Looping over project's module file editors never finds any resources even if project have additional resources

  • added via Resources and Images dialog
  • using {$RESOURCE binary.res} directive
  • using {$R filename.res filename.rc} syntax which no longer works
Community
  • 1
  • 1
Free Consulting
  • 4,300
  • 1
  • 29
  • 50

1 Answers1

0

(I have low reputation so cannot add a comment)

Project.ModuleFileCount always returns 1 and Project.ModuleFileEditors[0].FileName returns ProjectName.dpr

In XE3 I tested it is possible to enumerate all modules of project with the following code:

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

But in any case I always have Not found!!! message.

Denis Anisimov
  • 3,297
  • 1
  • 10
  • 18
  • The fact that you have not enough rep to comment is not justification for writing a non-answer. In what way does this answer the question that was asked? – David Heffernan Dec 29 '13 at 17:23
  • I think that topic starter uses wrong algorithm of module enumeration. – Denis Anisimov Dec 29 '13 at 17:27
  • I cannot say what your technique is wrong, but opening each owned module looks overkill for me. Anyway, the method of locating `IOTAProjectResource` editor for project (== owner module) demonstrated in the question works in Delphi 2007, and `Project.GetModuleFileCount` returns 2 (likewise, `GetModuleFileEditor(1).FileName` points to `.RES` file). – Free Consulting Dec 29 '13 at 18:46