2

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?

TomB
  • 750
  • 4
  • 17
  • See http://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 Dec 03 '14 at 21:08
  • Yes it's a test project - everything is in the same folder. – TomB Dec 03 '14 at 21:35
  • Are you doing a "compile" or a full "build"? – Jerry Dodge Dec 03 '14 at 21:36
  • @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 Dec 03 '14 at 21:43

1 Answers1

2

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 5
    The solution should be to add the rc file to the project via Shift-F11 or the corresponding menu command or button or context menu in the project manager. Editing the dpr file directly is often a source of weird behaviour. – Uwe Raabe Dec 03 '14 at 21:25
  • David, I don't quite understand what you mean by "put a rc file alongside". You mean you just open it, without adding to project? – TomB Dec 03 '14 at 21:37
  • I think the [docs](http://docwiki.embarcadero.com/RADStudio/en/Resource_file_%28Delphi%29) does not specifically discern between project source and units. Although I'm not sure. – Sertac Akyuz Dec 03 '14 at 21:37
  • "I think that you are probably best either using the IDE to manage resources or to compiler them yourself. " ...contrasting a comment on a recent q/a combo of mine... :-) – Jerry Dodge Dec 03 '14 at 21:40
  • I have observed something like that behavior. Creat fresh, add line save project, close (no build). Re-open, build. In some cases it seems to auto add the RC file to the project, then all is sweet. But mostly it does not. I was partly trying to avoid having to add the RC to a squillion projects, but also partly trying to understand what was going on. Other people were suggesting that you just add the line to the DPR. Weird. – TomB Dec 03 '14 at 21:40
  • @Jerry As you know, I prefer to compile resources myself. If you don't fancy that then let the ide do it, but do it all in the ide. It's the mix and match that's the problem here. – David Heffernan Dec 03 '14 at 21:42
  • @David Yes I suspect you are right. I'll just compile it myself and then just add the {$R dummy.res} to dpr. However that still leaves me wondering how I might do something like David suggested for someone who wanted to vary the icon based on the platform e.g.`{$IFDEF Win32} {$R 'MyAppIcon32.res' 'MyAppIcon32.rc'} {$ENDIF} {$IFDEF Win64} {$R 'MyAppIcon64.res' 'MyAppIcon64.rc'} {$ENDIF}` – TomB Dec 03 '14 at 21:59
  • I doubt those conditionals play well with the ide – David Heffernan Dec 03 '14 at 22:05
  • That's when I typically create a brand new unit called `AppInit`, move all the DPR code to it, and only call one function from the DPR. Disadvantage is you lose the ability to acknowledge the type of application and have to manually do a lot more (version info, VCL styles, etc.). But yeah, the IDE "owns" the DPR file. – Jerry Dodge Dec 03 '14 at 22:46
  • Thanks Jerry. That is a pretty significant disadvantage. – TomB Dec 03 '14 at 23:26