Low level code |
Top Previous Next |
What is not translated > Low level code It is not possible to convert code automatically, that uses low level tricky pointer manipulation, which in addition may rely on the memory layout of the intrinsic Delphi types as in the following example:
procedure SetTBytesLength(var b : TBytes; len : integer); type PDynArrayRec = ^TDynArrayRec; TDynArrayRec = packed record RefCnt: LongInt; Length: NativeInt; end; var p : Pointer; oldL, minL : NativeInt; begin if len = 0 then begin b := nil end else begin p := Pointer(b); oldL := 0; if p <> nil then begin dec(PByte(p), SizeOf(TDynArrayRec)); oldL := PDynArrayRec(p).Length end;
if (p = nil) or (PDynArrayRec(p).RefCnt = 1) then begin ReallocMem(p, SizeOf(TDynArrayRec) + len) end else begin ...
For other compilers then C++Builder Delphi2Cpp II uses a std::vector as substitute for a dynamic array.std::vector has no RefCnt ond no Length element. The translation of the example case is fortunately easy because an existing method can be used.
void SetTBytesLength(TBytes& B, int Len) { B.resize(Len); }
|
This page belongs to the DelphiXE2Cpp11 Documentation |
DelphiXE2Cpp11 home Content |