- string is not ordinal -> can not be cast.
Is the fact that a sequence of 4 characters is NOT always a Pascal string that hard to understand ????????
n bytes, as in any number of bytes, can be interpreted in quite a few ways. 4 bytes, no matter how they appear in the source code, can be interpreted as ANY entity that uses 4 bytes, such as a DWORD. The fact that the value is being specified with characters instead of digits is irrelevant. if it were relevant we couldn't represent hex numbers because A thru F are characters and because of that $abcdef couldn't be a number, it would have to be a string of 6 characters. Fortunately, the compiler is smart enough to interpret those characters as numbers when they are preceded by a "$" sign. In "const CONSTD = DWORD('abcd');" the compiler is being explicitly told to interpret 'abcd' as the 4 byte sequence in a DWORD because the 'abcd' is cast as a DWORD... hey compiler... those 4 bytes there... those are the 4 bytes that make up a DWORD... capisce ?? (unfortunately the compiler not capisce and... many Pascal users not capisce either!)
Also unfortunate is that explaining the obvious again will not change the result. Because of that, I'm going to openly patronize those who refuse to understand the obvious by declaring you are all absolutely right, yes, you are all absolutely right. It still won't change the result but, hopefully, I won't have to read any more preposterous non sense.
in DWORD('abcd'), 'abcd' is not a string, it's just a sequence of 4 characters, that's all it is. Just like 'a' isn't a string, it's a sequence of 1 character, that's it, that's all it is. and guess what... a sequence of 4 characters is a sequence of 4 bytes and a sequence of 4 bytes also goes by the name of DWORD which, amazingly, happens to be an ordinal type (at least in 32 bit.)
What's next ??? 111111 is a string too ? should DWORD(1111) store the 1111 somewhere thus making it invalid as a constant value ??? The arguments being presented are literally absurd and preposterous.
Again and again, the compiler is being explicitly told to interpret the 4 characters 'abcd' as a DWORD. It's that simple and, the compiler fails miserably at this absolutely trivial task. Worst part, FPC users defend this absurdity. No wonder this is the language of writable constants.