Unfortunately, both aren't suitable for case constants, as in Peter's example. (Though I don't know if they're frequently used that way.)
To speak for myself, no. I looked into a typical Mac OS program with 300.000 lines of code. It had 443 case statements, but none of them used FourCharCodes as case constants.
They become a lot more prevalent in Mac OS X carbon events code and NIB, as you use them for all the commands and status displays and controls and such.
I believe the limitation is acceptable, at least not serious enough to come up with tricks (that make source code more obscure). The case statement can be rewritten to an if statement.
it can, but a case statement is a lot more clear, and also has the added benefit of efficiency and checking for duplicated case elements.
{$define UInt32(s) ((Ord (substr((s),1,1)) shl 24) or (Ord (substr((s),2,1)) shl 16) or (Ord (substr((s),3,1)) shl 8) or Ord (substr((s),4,1))}
should work for s as a constant-string-literal or as a constant-identifier declared as a string-literal (presuming, of course, the string has at least four characters).
Ah, good idea! This patch should fix the crash and allow `SubStr' (and `Copy') with constant arguments in constant expressions (gale1.pas). (As usual, I've made other changes meanwhile, so I hope it will fit the 20030507 sources.)
This is good, but it does have the disadvantage/risk that it uses the input parameter four times and thus is at risk if the input parameter is a function call (which at best will be called four times and at worst will cause side effects which could introduce hideous bugs).
I don't suppose there is any way of making that macro work but only access the input parameter once? Peter.