#1 2011-03-24 02:38:58

thunya
Member
Registered: 2011-03-14
Posts: 6

RTTI has some problem with Delphi 2010

I try to test ObjectToJSON function from TCollection object.
No JSON content generate from that object.
Then I track down to TJSONSerializer.WriteObject.

tkClass: begin
  Obj := pointer(GetOrdProp(Value,pointer(P)));  // works also for CPU64
  if IsTSQLRecord then begin
    if not P^.PropType^^.ClassType.InheritsFrom(TSQLRecordMany) then begin
      HR(P);
      Add(PtrInt(Obj));
    end;
  end else
  if Obj<>nil then begin
    HR(P);
    if Obj.InheritsFrom(TCollection) then begin
      HR;
      ...
      ...
Obj := pointer(GetOrdProp(Value,pointer(P)));  // works also for CPU64

Always return nil to Obj. No JSON content generated

Offline

#2 2011-03-24 10:05:35

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

Re: RTTI has some problem with Delphi 2010

Two possibilities:

1. You try to serialize directly a TCollection object.
This is not handled yet: the TCollection must be a published property of another object.

So I've fixed this limitation. Now ObjectToJSON will be able to serialize directly a TCollection or a TStrings.
See http://synopse.info/fossil/info/8b22bf5bc8


2. It's because the TCollection instance is not existing in the published properties, IMHO.
You have to explicitly create the TCollection instance.

Take a look in SQLite3Commons.pas, in the TTestLowLevelTypes.EncodeDecodeJSON method.
You have here the regression tests about serialization of TCollTst.

They all passed with success with Delphi 2010.

Offline

#3 2011-03-24 10:22:06

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

Re: RTTI has some problem with Delphi 2010

I had also to update the reverse function.

Now JSONToObject will be able to unserialize directly a TCollection or a TStrings.
See http://synopse.info/fossil/info/97e16b4836

Offline

Board footer

Powered by FluxBB