Frank Heckenbach wrote:
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.)
Thanks for the speedy fix. Without trying the patch yet, I think the other changes might also be needed. When I tried changing the code to a run-time expression evaluation instead of a compile-time constant-expression evaluation to avoid the internal compiler error, I got an error message which in effect said the result of substr((s),1,1) wasn't a ordinal type and therefore the useage of substr((s),1,1) as an argument for the ord function was illegal. Changing it to:
ord(substr((s),1,1)[1])
did make the "not an ordinal type" problem go away. So, those trying to use the macro along with the patch may need to supplement the macro with string array indexing.
Gale Paeper gpaeper@empirenet.com