Difference between LongWord and Cardinal in Delphi XE?

2k views Asked by At

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);

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?

3

There are 3 answers

1
Paul-Jan On

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.

1
Jeroen Wiert Pluimers On

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

0
Warren  P On

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;