This code doesn't compile in XE :
const
InitSignature : array[0..3] of LongWord =
($67452301, $EFCDAB89, $98BADCFE, $10325476);
[DCC Error]: E2026 Constant expression expected
but this DOES:
const
InitSignature : array[0..3] of Cardinal =
($67452301, $EFCDAB89, $98BADCFE, $10325476);
开发者_StackOverflow社区
Assignable typed constants is ON.
If I cast all the array values to LongWord in the first sample the code compiles. But I cannot get what's the difference between LongWord and Cardinal?
I'm going to be bold, and state *there is no difference*. You arrived at the wrong conclusion somehow, and provided us with not enough information to help you out. I'm convinced you didn't paste a 1:1 copy of your code here, and you left out something relevant.
Could be an evil workmate who pasted a little inivisble unicode character before the opening parenthesis, and defined that same character as a function elsewhere. It could also be something a little more obvious.
Can you reproduce the issue in a clean project? Because I'm pretty sure you can't. If you can, post back. If you can't, post more context. By all means, prove me wrong.
You might have a function called longword somewhere in your code.
function LongWord: Integer;
begin
result := 0;
end;
procedure Foo;
const
InitSignature : array[0..3] of LongWord =
($67452301, $EFCDAB89, $98BADCFE, $10325476);
begin
//...
end;
The code below compiles fine in Delphi XE.
Show us more context of your code; it looks like something redefines LongWord
for you.
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
InitSignatureLongWords : array[0..3] of LongWord =
($67452301, $EFCDAB89, $98BADCFE, $10325476);
const
InitSignatureCardinals : array[0..3] of Cardinal =
($67452301, $EFCDAB89, $98BADCFE, $10325476);
begin
end.
--jeroen
精彩评论