program QuickCloneTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Quick.Commons,
Quick.Console,
Quick.JSON.Helper;
type
TMyObject = class
public
caption: string;
end;
var
jsonOutput: string;
myObject, myOtherObject: TMyObject;
begin
try
myObject := TMyObject.Create;
try
myOtherObject := TMyObject.Create;
try
myOtherObject.caption := 'Second object''s caption';
myObject.caption := 'First object''s caption';
jsonOutput := myObject.ToJson;
cout('Json is: ', ccYellow);
cout(jsonOutput, etInfo);
cout('', ccWhite);
myOtherObject.FromJson(jsonOutput);
cout('MyOtherObject''s caption is: ', ccYellow);
cout(myOtherObject.caption, etInfo);
cout('', ccWhite);
myOtherObject.Clone(myObject);
cout('After cloning, myOtherObject''s caption is: ', ccYellow);
cout(myOtherObject.caption, etInfo);
cout('', ccWhite);
myObject.caption := 'Changed';
myObject.FromJson(jsonOutput);
cout('MyObject''s caption is: ', ccYellow);
cout(myObject.caption, etInfo);
finally
myOtherObject.Free;
end;
finally
myObject.Free;
end;
ConsoleWaitForEnterKey;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Json is:
{
"caption": "First object's caption"
}
MyOtherObject's caption is:
Second object's caption
After cloning, myOtherObject's caption is:
Second object's caption
MyObject's caption is:
Changed
where I expected always "First object's caption".