Search code examples
delphidelphi-xedatamodule

Why main form can't access to DataModule's images and actions when project is open in Delphi XE?


My Delphi XE application was fine till a couple of days and I can't figure out what is wrong. My project layout:

  • Visual controls are on the main form
  • Actions and image lists for those controls are on a data module

When I open my project, the main form doesn't have any image or actions associated to any of the controls, even though they should be. When I compile I get the error message: "Module 'winMain' links to module 'modGeneral' which cannot be found in the current project. Do you wish to remove/redirect the links to another module?".

The work around: close the main form after I've opened the project, then open the module in the IDE by double-clicking it in the project manager (yes, it is present in the current project), then re-open the main form: all my actions and images are now correctly displayed.

What do you think, is that a known Delphi bug ? A problem with my project ?


Solution

  • Check your .dpr file. One way to reproduce your problem is to change the uses clause in it. Consider this example which works fine:

    program Project1;
    
    uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {DataModule2: TDataModule};
    
    {$R *.res}
    
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm1, Form1);
      Application.CreateForm(TDataModule2, DataModule2);
      Application.Run;
    end.
    

    The icon in the Project Manager looks as usual for a module with a dfm:

    Project Manager screenshot 1

    If you remove the comment, or comment it out:

    program Project1;
    
    uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas'; // {DataModule2: TDataModule};
    
    {$R *.res}
    
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm1, Form1);
      Application.CreateForm(TDataModule2, DataModule2);
      Application.Run;
    end.
    

    Here, the icon has changed:

    Project Manager screenshot 2

    ...and you get the errors you describe. You need to close and reopen the project for your changes to take effect.