2
votes

I'm working on taking control of some project options external to the IDE e.g. version numbering. I can do this OK if I either (i) compile the relevant RC file externally to create the RES file and include that in the DPR, or (ii) add the RC file to the project.

However, I cannot get it to work just by adding a line of the form {$R 'dummy.res' 'dummy.rc' } to the DPR. It will compile/build OK if and only if the RES file already exists. I'm using XE6 but I get the same behavior in XE and even Delphi 7.

But there are numerous answers that suggest that adding such a line to the DPR is all one needs to do. Can anyone clarify, please?

1
See stackoverflow.com/a/11782584 for a complete example. The quotes are only needed if there is a space in the filename (which probably shouldn't be necessary). Is the .rc file in the same folder as your project? - Ken White
Yes it's a test project - everything is in the same folder. - TomB
Are you doing a "compile" or a full "build"? - Jerry Dodge
@Ken Yes I saw your excellent versioninfo example, and that was what I used. As I said I can get it to work is if pre-compile the RC file (giving a RES file). But just adding that line to the DPR, does not cause the compiler to invoke the resource compiler, it just looks for the RES file. - TomB

1 Answers

2
votes

I've been able to reproduce something similar to what you describe. It may or may not be the same problem as you.

I create a new project and put a .rc file alongside the top level project files. Then I add this line to the project file:

{$R myresource.res myresource.rc }

Then I compile and no .res file appears. Then I save the project and re-compile, and now the .res file appears.

After analysing this series of events, I think I understand what is going on. Until you save the project, there is nothing in the .dproj file to trigger the resource compile. When you save the project, this appears in the .dproj file:

<RcCompile Include="myresource.rc">
    <Form>myresource.res</Form>
</RcCompile>

It's quite plausible that this is what is happening to you.

I think that you are probably best either using the IDE to manage resources or to compile them yourself. The former is done, for instance, using the Resources and Images action on the Project menu. The latter can be done with pre-build actions.