This is my synopsis of what you have done:
- You are working on a package project.
- You have added some files to the project using the Resources and Images dialog from the Project menu.
- You have added the line
{$R Project.dres}
to one of the units contained in that package.
The compiler then reports, at link time, that it has been asked to link multiple copies of the file Project.dres
. The compiler won't do this and discards one of the compiled resource files.
The key to understanding this can be found in your package's main file, the .dpk file. It will look like this:
package Package1;
{$R *.res}
{$R *.dres}
....
When you use the Resources and Images dialog in the IDE the IDE stores the information in the project file, the .dproj file, and also adds {$R *.dres}
to the main project source file. And that's the line that can be seen above. The *
in a $R
directive instructs the compiler to use the same base name as the file in which the $R
directive appears.
So this is how you end up with multiple references to the same .dres file. The compiler expands the {$R *.dres}
in your .dpk file into Project.dres
and links it.
The most natural solution would be to delete the {$R Project.dres}
from the .pas
source unit in which it appears.
However, it is possible that the reason why you placed it in the source file is that you use the source file in other projects and want it to stand alone. The source file contains the code that loads the resource and it makes sense to ensure that whenever a project includes this source file, it also includes the resource. A $R
directive will do that. But that's not compatible with using the IDE's Resources and Images dialog. That IDE mechanism relies on saving the information to .dproj files and is a project centric mechanism.
So, it you want the source .pas file to include the $R
directive here is what to do:
- Remove all the items from the Resources and Images dialog.
- Makes sure there are no references to the
.dres
file in any source file, including .dpk and .dpr files.
- Create a .rc resource script file that lists the resources you wish to include.
- Ask the compiler to compile the resource script and link it by including this directive in your .pas source file:
{$R images.res images.rc}
Obviously I've just invented a file name there, but you will no doubt pick something appropriate.