Search code examples
delphidehl

TVarData Differences between x86 and x64 Delphi


I couldn't find any explanation about TVarData in x64. There is a page in Help but it seems TVarData in x64 and TVarData in x86 are different. Actually I'm trying to compile DEHL for x64 target. But it says "Invalid typecast" on this line:(Source is TVarData)

Big := TBigCardinalVarData(Source).BigCardinalPtr^;

And TBigCardinalVarData is here:

TBigCardinalVarData = packed record
  VType: TVarType;
  Reserved1, Reserved2, Reserved3: Word;
  BigCardinalPtr: PBigCardinal;
  Reserved4: LongWord;
end;

It compiles in x86, but it refuses to compile in x64. I think the problem is in Word and LongWord variables. But I couldn't figure it yet.


Solution

  • The problem is the packed record declaration, the Packed Record Type Becomes Record Type in X64, so you must remove the "packed" from "packed record" in the declaration and instead use the ALIGN Directive.

    {$ALIGN 8}
    TBigCardinalVarData = record
      VType: TVarType;
      Reserved1, Reserved2, Reserved3: Word;
      BigCardinalPtr: PBigCardinal;
      Reserved4: LongWord;
    end;
    

    for more info read these entries