Gale Paeper wrote:
Frank Heckenbach wrote:
I thought of a macro encapsulating the code above.
{$define UInt32(s) ((((Ord (s[1]) * 256) + Ord (s[2])) * 256 + Ord (s[3])) * 256 + Ord (s[4]))}
I'm not sure if GPC supports it but Extended Pascal provides for using the substr required function in constant-expressions as long as none of the parameters are variable-access. In theory, a macro such as:
{$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.)
With this fix, I think this macro should work. BTW, I suggest to use `Ord (SubStr ((s), 4))' without a 3rd argument. This way you'll get a compile-time error if the argument is longer than 5 characters (because then the argument to `Ord' will not be a character).
Frank