tags:

views:

1111

answers:

6

Delphi sometimes adds {$R *.res} in front of the unit path in the .dpr file uses clauses, then I get a duplicated resources warning when trying to compile.

Anyone knows why the hell Delphi does that? I'm using Delphi 2009 but this happens since Delphi 2007 (maybe 2006 too)

A: 

I have Delphi 6 and it already happens. ;-(

+1  A: 

It is very annoying, happens without any obvious reasons and cannot be prevented from happening - as far as I know :(

gabr
+5  A: 

It depends on what else you've done to the .dpr file. Delphi expects that file to be layed out in a certain way, and if you've modified it in such a way that the internal IDE parsers are unable to correctly find certain things, it can guess wrong. Originally, the .dpr file was never intended for the user to modify at will, and so it can get confused. IFDEFS are the most common culprits which can confuse the IDE parser.

Allen Bauer
I removed everything from the dpr, there are no ifdefs, no code, nothing, and it keeps happening!
Fabio Gomes
@Gomes: Can you post the contents of the DPR?
Bruce McGee
+2  A: 

Perhaps posting your .dpr would help illustrate your problem. My project files look like this and give me no problem:

program Example;

{$R *.res}

uses
  Unit1 in 'Unit1.pas' {frmUnit1};

begin
  Application.Initialize;
  Application.CreateForm(TfrmUnit1, frmUnit1);
  Application.Run;
end.
Scott W
My {$R *.res} code is bellow the uses, maybe that is the problem. I've changed it here and will test it out.
Fabio Gomes
+2  A: 

I have acquired some "heuristics" to deal with fact that the IDE messes with the dpr:

  1. No "complicated" code in the main begin-end-block (i.e. stuff with variables or ifs :-)). Everything I need to be done there is swapped out into separate routines. This seems to make the IDE parser happier.
  2. If I need $IFDEFs in the uses clause I make a "proxy unit" which contains the $IFDEFed units and put that in the dpr's uses clause.
Ulrich Gerhardt
+1  A: 

Delphi adds {$R *.res} to your .dpr file to link the .res file that it generates into your application. E.g. if you save your project as MyProject.dpr, Delphi will create a file MyProject.res that contains your application icon and version information that you specify in Project Options in Delphi. Without this .res file, your .exe won't have an icon or version info.

If you get a duplicate resource warning, you probably have another {$R} compiler directive elsewhere in your code that also links in MyProject.res. It could be a duplicate {$R *.res} in your .dpr file, or a {$R MyProject.res} in another .pas file. Delete the other compiler directive instead of the one that Delphi generates automatically, and your project will compile just fine.

Jan Goyvaerts