Delphi XE中LongWord和Cardinal的区别?

发布于 2024-10-17 05:04:59 字数 430 浏览 2 评论 0原文

此代码无法在 XE 中编译:

const
    InitSignature : array[0..3] of LongWord =
        ($67452301, $EFCDAB89, $98BADCFE, $10325476);

[DCC 错误]:E2026 需要常量表达式

,但确实如此:

const
    InitSignature : array[0..3] of Cardinal =
    ($67452301, $EFCDAB89, $98BADCFE, $10325476);

可分配类型常量为 ON。

如果我在第一个示例中将所有数组值转换为 LongWord,代码就会编译。 但我不明白 LongWord 和 Cardinal 之间有什么区别?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笛声青案梦长安 2024-10-24 05:04:59

我将大胆地声明*没有差异*。您不知何故得出了错误的结论,并且没有向我们提供足够的信息来帮助您解决问题。我确信您没有在此处粘贴代码的 1:1 副本,并且您遗漏了一些相关内容。

可能是一个邪恶的同事在左括号前粘贴了一些不可见的 unicode 字符,并在其他地方将相同的字符定义为函数。它也可能是更明显的事情。

你能在一个干净的项目中重现这个问题吗?因为我很确定你做不到。如果可以的话,请回帖。如果不能,请发布更多上下文。无论如何,证明我错了。

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.

单挑你×的.吻 2024-10-24 05:04:59

您的代码中可能有一个名为 longword 的函数。

function LongWord: Integer;
begin
 result := 0;
end;

procedure Foo;
const
    InitSignature : array[0..3] of LongWord =
        ($67452301, $EFCDAB89, $98BADCFE, $10325476);
begin
  //...
end;

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;
避讳 2024-10-24 05:04:59

下面的代码在 Delphi XE 中编译良好。

向我们展示您的代码的更多上下文;它看起来像是为您重新定义了 LongWord

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.

——杰罗恩

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文