There is the following code (compiles under x32, Delphi XE7):

const varTypeMask = $0FFF; TExtData = packed record VExtType: LongWord; Reserved: LongWord; VPointer: Pointer; Dummy: LongWord; end; function ExtType(const Value: Variant): LongWord; begin if TVarData(Value).VType and varTypeMask <> 0 then Result := TVarData(Value).VType else Result := TExtData(Value).VExtType; end; 

When compiling for x64, we have an error:

 [dcc64 Error]: E2089 Invalid typecast 

with a link to the string: Result := TExtData(Value).VExtType;

How to fix?

    1 answer 1

    Obviously, for x64, the size of the type Variant and, accordingly, TVarData in bytes is different from the size of these types when compiled under x32. See the definition of TVarData . When compiling for x32, the TVarData size TVarData 16 bytes, and for x64 it is 24 bytes.

     TVarData = packed record case Integer of ... 1: (RawData: array [0..{$IFDEF CPUX64}5{$ELSE}3{$ENDIF}] of LongInt); 

    Therefore, to correct the error, you need to correct the definition of TExtData so that when compiling for x64 it is 24 bytes in size, and when compiling for x32 is still 16 bytes, then the compiler can always interpret Variant as TExtData .

    You can fix, for example, like this:

     TExtData = packed record VExtType: LongWord; // 4 Reserved: LongWord; // 4 VPointer: Pointer; // 4/8 DummyPointer: Pointer; // 4/8 end; // 16/24