开发者

Integer() in 64bit XE2

开发者 https://www.devze.com 2023-04-11 19:54 出处:网络
How would this be correct when on 64bi开发者_C百科t platform in XE2? type PRGB24 = ^TRGB24; TRGB24 = packed record

How would this be correct when on 64bi开发者_C百科t platform in XE2?

type
  PRGB24 = ^TRGB24;
  TRGB24 = packed record
    B: Byte;
    G: Byte;
    R: Byte;
  end;

var
  s1: pRGB24;
  ptrD: integer;

....

inc(Integer(s1), PtrD); <- gives error here "Left side cannot be assigned to"


Integer type is 32-bit long, pointer type is 64-bit long on 64-bit platform, hence the error. I can't test it now, but

inc(NativeInt(s1), PtrD);

should fix the problem.


BTW: Inc procedure can accept pointers, so normally there is no need to cast pointer to integer here. The same result can be obtained by

inc(PByte(s1), PtrD);

To avoid s1 casting at all is even better

inc(s1, PtrD);

but it changes the meaning of the code - its equivalent is

inc(PByte(s1), PtrD * SizeOf(TRGB24 ));


Whilst NativeInt will get the job done I would rather cast it to PByte:

inc(PByte(s1), PtrD);

Since s1 is a pointer, casting to another pointer is more natural – it's not possible for there to be a pointer width error now or in the future.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号