Please help me to understand why AV is going on here (http://pastebin.com/YkAqQ604):
Please help me to understand why AV is going on here (http://pastebin.com/YkAqQ604):
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Classes, System.JSON, Data.DBXJSONReflect;
function Marshal(AObject: TObject): string;
var
Marshaller: TJSONMarshal;
begin
Marshaller := TJSONMarshal.Create;
try
Result := Marshaller.Marshal(AObject).ToJSON;
finally
FreeAndNil(Marshaller);
end;
end;
function Unmarshal(AString: string): TStringList;
var
Unmarshaller: TJSONUnMarshal;
JV: TJSONValue;
begin
Unmarshaller := TJSONUnMarshal.Create;
try
JV := TJSONObject.ParseJSONValue(AString);
try
Result := Unmarshaller.Unmarshal(JV) as TStringList;
finally
FreeAndNil(JV);
end;
finally
FreeAndNil(Unmarshaller);
end;
end;
function MarshalUnmarshal: string;
var
StringList: TStringList;
Marshaled: string;
begin
StringList := TStringList.Create;
try
StringList.Text := 'abc';
Marshaled := Marshal(StringList);
finally
FreeAndNil(StringList);
end;
StringList := Unmarshal(Marshaled);
try
Result := StringList.Text;
finally
FreeAndNil(StringList);
end;
end;
begin
try
Writeln(MarshalUnmarshal);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
http://pastebin.com/YkAqQ604
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Classes, System.JSON, Data.DBXJSONReflect;
function Marshal(AObject: TObject): string;
var
Marshaller: TJSONMarshal;
begin
Marshaller := TJSONMarshal.Create;
try
Result := Marshaller.Marshal(AObject).ToJSON;
finally
FreeAndNil(Marshaller);
end;
end;
function Unmarshal(AString: string): TStringList;
var
Unmarshaller: TJSONUnMarshal;
JV: TJSONValue;
begin
Unmarshaller := TJSONUnMarshal.Create;
try
JV := TJSONObject.ParseJSONValue(AString);
try
Result := Unmarshaller.Unmarshal(JV) as TStringList;
finally
FreeAndNil(JV);
end;
finally
FreeAndNil(Unmarshaller);
end;
end;
function MarshalUnmarshal: string;
var
StringList: TStringList;
Marshaled: string;
begin
StringList := TStringList.Create;
try
StringList.Text := 'abc';
Marshaled := Marshal(StringList);
finally
FreeAndNil(StringList);
end;
StringList := Unmarshal(Marshaled);
try
Result := StringList.Text;
finally
FreeAndNil(StringList);
end;
end;
begin
try
Writeln(MarshalUnmarshal);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
http://pastebin.com/YkAqQ604
Comments
Post a Comment