Integer() 类型转换在 Delphi 64 位上不起作用

发布于 2025-01-02 15:25:58 字数 282 浏览 3 评论 0原文

我有以下代码:

inc(integer(DestPixel), DestDelta); //DestPixel: PColorRGB; DestDelta: integer;

这在 32 位平台上运行良好。如果我在编译器中将平台更改为 64 位,编译器会发出以下错误:

E2064 左侧无法分配给

问题似乎出在 integer() 类型转换中。我该如何解决这个问题?

I have the following piece of code:

inc(integer(DestPixel), DestDelta); //DestPixel: PColorRGB; DestDelta: integer;

This works fine on 32-bit platforms. If I change the platform to 64-bit in the compiler the compiler emits this error:

E2064 Left side cannot be assigned to

The problem seems to be in the integer() typecast. How can I fix the problem?

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

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

发布评论

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

评论(1

乱世争霸 2025-01-09 15:25:58

在 64 位平台上,DestPixel 为 8 字节宽,Integer 为 4 字节,因此类型转换无效。您可以使用 NativeInt 来解决此问题。

inc(NativeInt(DestPixel), DestDelta);

NativeInt 类型与指针大小相同,因此根据输出目标在 4 字节到 8 字节宽之间浮动。

话虽如此,我个人会使用 PByte 进行类型转换,因为它更正确地描述了您正在执行的操作。

inc(PByte(DestPixel), DestDelta);

On the 64 bit platform, DestPixel is 8 bytes wide, Integer is 4 bytes and so the typecast is invalid. You can fix this problem by using NativeInt instead.

inc(NativeInt(DestPixel), DestDelta);

The NativeInt type is the same size as a pointer and so floats between 4 bytes and 8 bytes wide depending on the output target.

Having said that, I personally would typecast with PByte because that more correctly describes the operation you are performing.

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