Ken Bourassa
Ken Bourassa

Reputation: 6467

How to automatically copy resources to the DCU output folder

I would like to know, is there a way to automatically make the IDE/Compiler/other copy all the resource that needs to be linked with the DCU to the DCU output folder.

I often use forms that I pre-compile to avoid the needs to recompile the unit all the time in my main projects. The DCU gets updated, but we need to copy the DFM manually everytime it changes. Same goes for any {$R *.res} specified. Maybe we could maintain those file directly in the DCU folder... but doesn't quite make sense to have a .DFM in a different folder than a .PAS

I looked for a compiler switch that would do it... Unsuccesfully.

Anyone knows if/how it can be achieved?

I'm using Delphi 2010

Upvotes: 9

Views: 2509

Answers (3)

IceCold
IceCold

Reputation: 21124

There is an issue when we use precompiled libraries. The compiler will find the DCUs via the Library Paths. However, the resources (DFM, RES, RC) files are not compiled into the DCUs. They are linked later. So, the compiler still needs to find them and here comes the problem. Since the DFM files are located in the same folder as the PAS files, we cannot point the compiler to the folder where the PAS files are. It will use those PAS files instead of the DCU files. And we lose the whole advantage of having precompiled units! The solution is to copy the resource files into the DCU folder. We can do it by hand, or we can do it in a post-build event that uses environment variables.

@echo on

xcopy "$(PROJECTDIR)\*.dfm" "$(ProductVersion)\$(Platform)\$(Config)" /Y
xcopy "$(PROJECTDIR)\*.res" "$(ProductVersion)\$(Platform)\$(Config)" /Y
xcopy "$(PROJECTDIR)\*.rc"  "$(ProductVersion)\$(Platform)\$(Config)" /Y

echo Copy over

[Stack Overflow says that I have to disclose that I am affiliated with that website.]

Upvotes: 0

vcldeveloper
vcldeveloper

Reputation: 7489

For *.res files you can specify output path in "Project Options | Resource Compiler | Directories and Conditionals | Output directory for .res files"

But for *.DFM files you have to use skamradt's suggestion (Post Build event).

Upvotes: 3

skamradt
skamradt

Reputation: 15538

You could create a simple Post Build event which performed the copying. That way whenever you did a build, the system would copy the necessary files for you. The build events are available from the Project Options menu, there is a Pre-build and a Post-Build script.

Upvotes: 6

Related Questions