Question

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

No correct solution

OTHER TIPS

(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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top