Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi adding {$R *.res} in the .dpr file

Tags:

delphi

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)

like image 369
Fabio Gomes Avatar asked Nov 25 '08 16:11

Fabio Gomes


5 Answers

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.

like image 62
Allen Bauer Avatar answered Nov 10 '22 01:11

Allen Bauer


The issue why the Delphi is adding you these "wrong" {$R} and {$R *.res} texts is hidden in the DPROJ file. Just open the DPROJ file with a text editor and search for the $R *.res and remove these tags:

<DCCReference Include="..\..\..\Core\IF.Common\uTranslation.Types.pas">
  <Form>$R *.res</Form>
</DCCReference>

Change that to

<DCCReference Include="..\..\..\Core\IF.Common\uTranslation.Types.pas"/>

Now you will not get the crappy text in your project (until next time IDE fails adding such thing to DPROJ file.

like image 25
Z.B. Avatar answered Nov 10 '22 03:11

Z.B.


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.
like image 7
Scott W Avatar answered Nov 10 '22 01:11

Scott W


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.

like image 5
Jan Goyvaerts Avatar answered Nov 10 '22 01:11

Jan Goyvaerts


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.
like image 4
Uli Gerhardt Avatar answered Nov 10 '22 03:11

Uli Gerhardt