开发者

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 displaye开发者_运维百科d.

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


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:

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

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:

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

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


TOndrej's answer is complete and correct. I have just a small addition which I maybe should post as comment but I'm afraid it won't be noticeable. I faced with the described error after unit renaming and project file refactoring (actually I removed all the in and comments from uses section). I returned the required pattern in the uses section but I still got the error. My mistake was an alignment that I added to comments in uses section:

DMMain     in 'DMMain.pas'     {fdmMain    : TDataModule},
DMIndex    in 'DMIndex.pas'    {fdmIndex   : TDataModule},

Surprisingly it really matters. Removing the alignment

DMMain     in 'DMMain.pas'     {fdmMain: TDataModule},
DMIndex    in 'DMIndex.pas'    {fdmIndex: TDataModule},

fixed the error and I got things working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜