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

标签 delphi 64-bit integer delphi-xe2 typecast-operator

我有以下代码:

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

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

E2064 Left side cannot be assigned to

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

最佳答案

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

inc(NativeInt(DestPixel), DestDelta);

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

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

inc(PByte(DestPixel), DestDelta);

关于delphi - Integer() 类型转换在 Delphi 64 位上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9151190/

相关文章:

python - 考虑python发行版wx

java - 字符串无法转换为int数组和ASCII

python - 初学者Python程序

delphi - TListView 和多个按钮

assembly - x64 SSE 数据类型

delphi - 使用 TStreamReader 和 TStringList 处理非常大的文本文件

C++ 移位位

Java - 从字符串中获取整数

delphi - 由 DelphiZXingQRCode 编码的 QR 码无法在 ErrorCorrectionLevel > Low 的情况下解码

delphi - 您可以永久动态添加 Delphi 组合框项吗?