Integer() in 64bit XE2
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.
精彩评论