3

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 ?

jonjbar
  • 3,896
  • 1
  • 25
  • 46
  • 1
    If you use source code control, you can do a checkin, then revert to a few days before the problem occurred, and see if you still have trouble. If the trouble goes away, it's something that happened in your project, and you can use the diffs to see what happened. – Chris Thornton Sep 14 '11 at 13:30
  • I have projects which are using the same method (visual in forms, non-visual in module) and I have no issue with my Delphi XE. I never use it, but there's a Clean menu item in the context menu of the project... maybe it can solve sth... (do a backup before...) – Whiler Sep 14 '11 at 14:34
  • @Chris Now that I know the source of the problem, looking through the diffs tells me the day this happened, but I can't understand why: Delphi changed it, or the automated build... I sure didn't change that manually. Thanks for your suggestion. – jonjbar Sep 14 '11 at 16:06

2 Answers2

7

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.

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • Along the same lines, removing the form's ability to see the data module could cause the same kind of problem, removing something from the implementation section `uses` clause for instance. – Warren P Sep 14 '11 at 15:34
  • In addition, you can use `Project|Options|Forms`, make sure that both your main form and datamodule are in the auto-create list, and then move the datamodule up to be created first. (It won't affect which is the main form, because a datamodule can't be one.) This ensures that the datamodule is created before the main form, both at design and runtime, so that you can access items in the datamodule safely in your main form's code. – Ken White Sep 14 '11 at 15:38
  • That was it TOndrej. I had in my project "m_Cli_General in 'Src\m_Cli_General.pas' {item: TDataModule}" and changed it to "m_Cli_General in 'Src\m_Cli_General.pas' {modGeneral: TmodGeneral}" which solved the problem. I don't know how this happened though. Thanks a lot – jonjbar Sep 14 '11 at 15:51
0

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.

Fr0sT
  • 2,959
  • 2
  • 25
  • 18
  • Maybe the compiler rejects code looking too much like FORTRAN (or COBOL) on a punched card ;) – mjn May 03 '14 at 11:57