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)
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.
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.
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.
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.
I have acquired some "heuristics" to deal with fact that the IDE messes with the dpr:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With