#1 2015-11-13 19:15:03

vsj
Member
Registered: 2012-06-26
Posts: 4

TDynArray.SaveToJSON Access Violation on D2007

Hi! Does D2007 is still supported?

This simple test on TDynArray works on XE7 but not on D2007.
When I remove the record property Valor, it works.
It looks like a bug with Integers (and Booleans).

  TRec = packed record
    Nome: string;
    Valor: Integer;
  end;
  TRecs = array of TRec;

procedure Test;
var
  t: TRecs;
  d: TDynArray;
  i: Integer;
begin
  SetLength(t, 5);
  d.Init(TypeInfo(TRecs), t);

  for i := 0 to Length(t) - 1 do
  begin
    t[i].Nome := 'Nome' + IntToStr(i);
    t[i].Valor := 1;
  end;

  ShowMessage(d.SaveToJSON);
end;

Here is the Access Violation message.

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0047114F in module 'Project1.exe'. Read of address 00000001'.
---------------------------
Break   Continue   Help   
---------------------------

Offline

#2 2015-11-13 20:12:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: TDynArray.SaveToJSON Access Violation on D2007

Under Delphi 2007, the needed RTTI is missing.

Use RegisterCustomJSONSerializerFromText() as documented http://synopse.info/files/html/Synopse% … #TITLE_224

Offline

Board footer

Powered by FluxBB