Hi! i need some help with XE7 :)
Hi! i need some help with XE7 :)
i'm triing to use parse to store and read a simple object , like a tdocument, something like this:
trow = class
code : string ;
description : string ;
end;
trows = TobjectList;
tdoc = class
someinfo: string ;
etc etc : tdate ;
rows : trows;
end;
i can easily mashall it , with "tjson.ObjectToJsonObject(doc)" but i can't unmarshall it ...
with tjson.JsonToObject(ajson) it not raise exception but not convert..
so i tried to create a manual marshal for Rows in document, and i have same problem. can marshall witout problem, but in unmarshalling procedure i don't have data object initialized so i have a access violation.....
there's some "initialization" procedure to call before?
thanks
i'm triing to use parse to store and read a simple object , like a tdocument, something like this:
trow = class
code : string ;
description : string ;
end;
trows = TobjectList
tdoc = class
someinfo: string ;
etc etc : tdate ;
rows : trows;
end;
i can easily mashall it , with "tjson.ObjectToJsonObject(doc)" but i can't unmarshall it ...
with tjson.JsonToObject
so i tried to create a manual marshal for Rows in document, and i have same problem. can marshall witout problem, but in unmarshalling procedure i don't have data object initialized so i have a access violation.....
there's some "initialization" procedure to call before?
thanks
Maybe our topic can help you - http://18delphi.blogspot.ru/2015/02/mindstream-how-we-develop-software-for.html
ReplyDeleteHow have you registered converter for trows class and rows field?
ReplyDeleteYou need manually write code:
ReplyDeleterows := trows.Create;
NOT in constructor, but where you UNMARSHAL your object.
Like this:
class function TmsSerializeController.DeSerialize(const aFileName: string)
: TmsDiagramm;
var
l_UnMarshal: TJSONUnMarshal;
l_StringList: TStringList;
begin
try
l_UnMarshal := TJSONUnMarshal.Create;
l_UnMarshal.RegisterReverter(TmsDiagramm, 'FShapeList',
procedure(Data: TObject; Field: String; Args: TListOfObjects)
var
l_Object: TObject;
l_Diagramm: TmsDiagramm;
l_msShape: TmsShape;
begin
l_Diagramm := TmsDiagramm(Data);
l_Diagramm.ShapeList := TmsShapeList.Create;
assert(l_Diagramm <> nil);
for l_Object in Args do
begin
l_msShape := l_Object as TmsShape;
l_Diagramm.ShapeList.Add(l_msShape);
end
end);
FShapeList => rows
TmsDiagramm => tdoc
ReplyDeleteThanks, i'll try! In my test i have problem with Args too. It was nil :(
ReplyDeleteYou need register CONVERTER and REVERTER
ReplyDeletel_Marshal.RegisterConverter(TmsShapeContainer, 'fList',
ReplyDeletefunction(Data: TObject; Field: string): TListOfObjects
var l_Shape : TmsShape;
l_Index: integer;
begin
SetLength(Result, (Data As TmsShapeContainer).fList.Count);
l_Index := 0;
for l_Shape in (Data As TmsShapeContainer).fList do
begin
Result[l_Index] := l_Shape;
Inc(l_Index);
end;
end
);
l_Marshal.RegisterConverter(TmsDiagramm, 'FShapeList',
ReplyDeletefunction(Data: TObject; Field: string): TListOfObjects
var
l_Shape: ImsShape;
l_Index: Integer;
begin
assert(Field = 'FShapeList');
SetLength(Result, (Data As TmsDiagramm).ShapeList.Count);
l_Index := 0;
for l_Shape in (Data As TmsDiagramm).ShapeList do
begin
Result[l_Index] := l_Shape.HackInstance;
Inc(l_Index);
end; // for l_Shape
end);
l_UnMarshal.RegisterReverter(TmsDiagramm, 'FShapeList',
ReplyDeleteprocedure(Data: TObject; Field: String; Args: TListOfObjects)
var
l_Object: TObject;
l_Diagramm: TmsDiagramm;
l_msShape: TmsShape;
begin
l_Diagramm := TmsDiagramm(Data);
l_Diagramm.ShapeList := TmsShapeList.Create;
assert(l_Diagramm <> nil);
for l_Object in Args do
begin
l_msShape := l_Object as TmsShape;
l_Diagramm.ShapeList.Add(l_msShape);
end
end);
TmsDiagramm == tdoc
ReplyDeleteFShapeList == rows
TmsShape == trows
Have you got the clue idea?
Maybe you send ve your code and I'll try ti fix it?
Hi! I tried but in reverter procs Args paramter is always nil :( i suppose there's some difference between xe6 and xe7... TJSONUnMarshal.unmarshall not exists. there's a CreateObject method instead ....
ReplyDeletecan i attach my test project?
o my god, i found the problem .... i used tJsonmarshall/ unmarshall of REST.JSONREFLECT unit ....... i MUST use data.dbxjsonreflect ....... Marco Cantù why not change method name? :)
ReplyDelete