#1 2015-06-23 20:29:51

Junior/RO
Member
Registered: 2011-05-13
Posts: 201

Delphi 7, RegisterCustomJSONSerializerFromText() and TypeInfo()

Ab, have you seen this?

If I try to serialize a array to Json with TDynArray.SaveToJson, Delphi 7 give me this compiler error:

  TEspecieCategorias = packed record
    EspecieID: Integer;
    Categorias: TCategorias;
    CT: Double;
    CTR: Double;
  end;

[...]

  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TEspecieCategorias), __TEspecieCategorias);

[Error]: Type 'TEspecieCategorias' has no type info.

But if I add a string field, then Delphi will generate type info.

  TEspecieCategorias = packed record
    EspecieID: Integer;
    Categorias: TCategorias;
    CT: Double;
    CTR: Double;
    Dummy: string;   // <--------- don't use for nothing
  end;

[...]

  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TEspecieCategorias), __TEspecieCategorias);

Then Delphi 7 will compile and everything will work. Very weird.

Question: The record type need to be packed?

Offline

#2 2015-06-24 05:33:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: Delphi 7, RegisterCustomJSONSerializerFromText() and TypeInfo()

Yes it must be packed.

Please check the doc.

Offline

Board footer

Powered by FluxBB