#1 2016-10-14 22:53:22

igors233
Member
Registered: 2012-09-10
Posts: 241

Serialization of variant records

I've noticed that records with variant parts are fully serialzed with RecordSaveJson, example is TRect.

var
  Temp: RawUtf8;
  R: TRect;
begin
  R := Rect(50, 50, 100, 100);
  Temp := RecordSaveJSON(R, TypeInfo(TRect));
  ShowMessage(Temp);
end;

Result is: {"Left":50,"Top":50,"Right":100,"Bottom":100,"TopLeft":{"X":50,"Y":50},"BottomRight":{"X":100,"Y":100}}

All values are correct of course but TopLeft and BottomRight parts are not needed, if there's an easy way to recognize variant parts in records solution would be to only use first part.

Offline

#2 2016-10-15 07:54:54

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

Re: Serialization of variant records

Define text serialization of the record with only the needed fields.

Offline

#3 2016-10-16 02:08:04

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Serialization of variant records

> Define text serialization of the record with only the needed fields.

Text serialization works but it's easier to rely on RTTI for the job. Have you tried to see if that's possible, that is detect record has variant definition? If not I can add it to my ToDo list and try to find a solution at some point.

Offline

Board footer

Powered by FluxBB