#1 2015-02-05 20:06:19

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Access Violation while record serializing

Hello,

I have problem when I'm trying to call service function via interfaces. When function has record param, then Access Violation is raised while executing. After small investigation I found where exists the problem. The problem occurs while serializing record parameter. I wrote small demo example:

  
type 
  TTestRecord = record
    Int: Integer;
    Bool: Boolean;
    Text: String;
  end;

procedure Test;
var
  tw: TTextWriter;
  rec: TTestRecord;
  stream: TStream;
begin
  stream := TMemoryStream.Create;
  try
    tw := TTextWriter.Create(stream);
    tw.AddRecordJSON(rec, TypeInfo(TTestRecord));
  finally
    stream.Free;
  end;
end;

The Access Violation exception is raised in line: tw.AddRecordJSON(rec, TypeInfo(TTestRecord));

But if definition of the record is changed to:

  TTestRecord = record
    Int: Integer;
    Text: String;
    Bool: Boolean;
  end;

then everything works correctly. I'm using Delphi XE4Pro, and current version of mORMot.

best regards
Adam Siwon


best regards
Adam Siwon

Offline

#2 2015-02-05 21:55:30

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

Re: Access Violation while record serializing

Record should be packed

Offline

#3 2015-02-05 22:18:59

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Access Violation while record serializing

Hello,

thank you very much. Now it works as expected. It would be nice to add this information to the documentation. In sections 10.1.3. Record serialization and 10.1.3.1. Automatic serialization via Enhanced RTTI there is no direct information about this requirement.

best regards
Adam Siwon

Last edited by ASiwon (2015-02-05 22:19:35)


best regards
Adam Siwon

Offline

#4 2015-02-06 10:10:20

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

Re: Access Violation while record serializing

It is written everywhere in the documentation.
Every record in the documentation is defined as "= packed record".
But it was not clear enough.
I've updated the documentation.

Thanks for the feedback.

Offline

#5 2015-02-06 18:41:29

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Access Violation while record serializing

Please do not be angry with me. mORMot documentation is really huge and sometime I have problem to find required information.

I have another documentation related question. In section 5.3.1. Return a list of objects exists example:

var aList: TObjectList<TSQLBaby>;
 aMale: TSQLBaby;
...
aList := Client.RetrieveObjectList<TSQLBaby>('Name LIKE ? AND Sex = ?' ,['A%' ,ord(sMale)]);
try
 for aMale in aList do
 DoSomethingWith(aMale);
finally
 aList.Free;
end;

But in mORMot code function RetrieveObjectList doesn't exists. I think this line in example should looks like:

aList := Client.RetrieveList<TSQLBaby>('Name LIKE ? AND Sex = ?' ,['A%' ,ord(sMale)]);

best regards
Adam Siwon


best regards
Adam Siwon

Offline

#6 2015-02-07 08:19:19

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

Re: Access Violation while record serializing

No problem Adam - on the contrary, any feedback about the documentation is worth telling!
It is difficult to reflect all the API changes in real-time, without introducing any error.
Most of the API is generated from the sources, so should be almost accurate, but the high level presentation code needs to be proven by hand.
Should be fixed by http://synopse.info/fossil/info/4a18c1883f

Thanks for the feedback.

Offline

Board footer

Powered by FluxBB