4

I have a rc entry:

{CC6C210B-2EAC-4F6C-89E7-0D2FEFFCE278}  8000  "MyFile.txt"

When I compile the rc file with cgrc.exe or brcc32.exe, I encounter this error:

[BRCC32 Error] system.core.rc(1): expected exponent value, not 'a'

This is due to the resource name "CC6C210B-2EAC" was interpreted as exponent value (-2EA). The A character after -2E is not valid exponent value.

If I change the rc entry to something like

{CC6C210B-2E2C-4F6C-89E7-0D2FEFFCE278}  8000  "MyFile.txt"

The resource compile without any error.

Unfortunately, I can't simply change the resource name as it has been widely used. Is there any ways to make rc do not interpret resource name as exponent value?

Chau Chee Yang
  • 18,422
  • 16
  • 68
  • 132

2 Answers2

0

I'm not so sure it was a good idea to use a GUID as resource name. If you really want to do that, you might want to "encode" it as a "normal" identifier, e.g.

_CC6C210B_2EAC_4F6C_89E7_0D2FEFFCE278  8000  "MyFile.txt"

You just write a set of simple routines to "encode" and "decode" such a value between a normal GUID string and the "encoded" form.

function DecodeToGUID(const renamedGUID: string): string;
begin
  Result := '{' + Copy(ReplaceString(renamedGUID, '_', '-', [rfReplaceAll]), 2, MaxInt)) + '}';
end;

I'll leave the implementation of the other routine to your imagination. ;-)


Update

If you put the ID in quotes, it should compile, with rc.exe. Without the quotes, the resource compiler will treat it as a preprocessor directive and get terribly confused:

"{CC6C210B-2EAC-4F6C-89E7-0D2FEFFCE278}"  8000  "MyFile.txt"

I tested this with Microsoft's rc.exe. Embarcadero's brcc32.exe will still give an error:

Error resrc.rc 1 1: Expecting resource name or resource type name

So if you want to use that, or the built in resource compiler of the IDE, you'll have to use something like the renamed GUIDs as described above.

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • What's bad about using a GUID? It doesn't seem unreasonable to me. Could you give some reasons for that advice since I guess I may be missing something. – David Heffernan Aug 20 '11 at 11:16
  • @David: it is just a string, but you see what happens. I would stay with the usual _, A-Z, 0-9 scheme, to be sure. – Rudy Velthuis Aug 20 '11 at 13:37
  • I think I'd prefer to use better tools! – David Heffernan Aug 20 '11 at 13:43
  • I prefer to use the tools in the IDE. Add an .rc file to your Delphi project, and it will be compiled automatically. Why should I use a command line tool belonging to another compiler instead? – Rudy Velthuis Aug 20 '11 at 14:06
  • FWIW, I just tried with Microsoft's RC.exe, and I get the same error. So, well, GUID strings are probably not a good idea: `resrc.rc(1) : error RC2021: expected exponent value, not 'A' C:\Users\Administrator\RCa04016(2) : fatal error RC1116: RC terminating after preprocessor errors` – Rudy Velthuis Aug 20 '11 at 14:21
  • When those tools don't function correctly I always prefer to ship a better product than accept needless limitations. – David Heffernan Aug 20 '11 at 14:23
  • @David: you would write your own resource compiler, or what did you mean? I don't think that not accepting a rather unusual identifier name is a big problem. – Rudy Velthuis Aug 20 '11 at 14:34
  • When I wanted to include 256px icons in my app I used a tool that supported them rather then the Emba supplied tool. That was clearly better than shipping without 256px icons.g without 256px icons. – David Heffernan Aug 20 '11 at 14:37
  • 1
    @David: not sure how that matters. We are talking about ID names, not about the accepted formats. In Delphi, C, C# etc. identifiers also have their restrictions. – Rudy Velthuis Aug 20 '11 at 14:43
  • I was talking about principles. Anyway, as your experiments show, rc beats brcc32, again. Resource identifiers are strings and not subject to language identifier constraints. er constraints. – David Heffernan Aug 20 '11 at 16:16
  • I use GUID as resource name is because I am lazy to create names for the resource items. The resource name play no meaningful role in my usage. Renaming the GUID as you suggested works but I think I will not do that. I will rather re-generate new GUID if the GUID cause exponent problem again. For used GUID, I will have to replace it one by one. – Chau Chee Yang Aug 21 '11 at 10:29
0

I recommend that you use the Microsoft resource compiler rc. According to the documentation for rc, the first token of a resource definition should be a name or a 16 bit integer. Why brcc32 wants to interpret this as a real value is quite beyond me.

If this doesn't work try enclosing the GUID in quotes, " rather than '.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Delphi IDE doesn't support Microsoft resource compiler rc directly. I will stay with cgrc or brcc32. Enclosing GUID with double quotes solve my problem but seems redundant. I think I will stay with pure GUID and avoid generating those problematic GUID. For those persisted GUID use else where, I will dig out one by one and replaced it with new GUID. I think this is some kind of resource compiler bug that is beyond our control. Unless we have cgrc or brcc32 source code to amend this bug. – Chau Chee Yang Aug 21 '11 at 10:25
  • 1
    use a pre build action and you can you can use any tools you like. No need to be constrained. I'm sorry that Rudy and I were not able to be of any help to you. – David Heffernan Aug 21 '11 at 10:35