Delphi XE中LongWord和Cardinal的区别?
此代码无法在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将大胆地声明*没有差异*。您不知何故得出了错误的结论,并且没有向我们提供足够的信息来帮助您解决问题。我确信您没有在此处粘贴代码的 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.
您的代码中可能有一个名为 longword 的函数。
You might have a function called longword somewhere in your code.
下面的代码在 Delphi XE 中编译良好。
向我们展示您的代码的更多上下文;它看起来像是为您重新定义了
LongWord
。——杰罗恩
The code below compiles fine in Delphi XE.
Show us more context of your code; it looks like something redefines
LongWord
for you.--jeroen