#1 2024-03-07 08:17:02

tfopc
Member
Registered: 2024-01-08
Posts: 11

Record serialization of static arrays (Delphi7, no rtti-infos)

Hi,
is it possible to serialize a record like this with definition RegisterFromText and without changing the record type (TTest) definition?

type TEnum = (eTagUnknown,eTagOne,eTagTwo)

     TTest = record
              id: cardinal;
              test: string;
              prices: array[1..3] of double;
              tags[eTagOne..eTagTwo] of integer;
             end;
const __TTest = 'id:cardinal;test:string;prices: array of double;tags: array of integer';

I have tried registriation with:

Rtti.RegisterTypes([TypeInfo(TEnum)]);
Rtti.RegisterFromText(TypeInfo(TTestRecord),__TTest);

but i get the error/exception on RegisterFromText:

Rtti.RegisterFromText(TTestRecord): text definition  covers 16 bytes, but RTTI defined 40

Offline

#2 2024-03-07 08:47:41

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

Re: Record serialization of static arrays (Delphi7, no rtti-infos)

You can't mix dynamic arrays (array of) and static arrays (array[1..3] of), because their are NOT the same type in memory and in the RTL.
And static arrays are not yet supported in RegisterFromText().

What you could do is manually expand the static arrays:

const __TTest = 'id:cardinal;test:string;price1,price2,price3: double; tagOne,tagTwo:integer';

But it won't make the expected JSON I guess.

Offline

Board footer

Powered by FluxBB