Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: IniFiles VS JSON


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Nov 5, 2014 1:13 AM Last Post By: Zivota Milic
Zivota Milic

Posts: 35
Registered: 4/4/08
IniFiles VS JSON  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 3, 2014 10:59 PM
Hello,

I saw a nice video that shows the advantages to use a JSON to save a configuration of my class compared to a inifile.

My question is: does it work if I have a generics list in my class?

example

TStudent = Class(TObject)
private
FName : String;
public
property Name : String read FName write FName;
end;

TClassRoom = class(TObject)
private
FLista : TList<TStudent>;
public
property Lista : TList<TStudent> read FLista;
end;

I want save a configuration of my class TClassRoom and in particular a content of the list as array. Is it possible?
Eli M

Posts: 1,346
Registered: 11/9/13
Re: IniFiles VS JSON  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 4, 2014 9:21 PM   in response to: Zivota Milic in response to: Zivota Milic
Will this work?

uses REST.JSON; // Also new System.JSON
 
procedure TForm1.Button1Click(Sender: TObject);
var
  Foo: TFoo;
begin
  Foo := TFoo.Create;
  try
    Foo.Foo := 'Hello World';
    Foo.Fee := 42;
    Memo1.Lines.Text := TJson.ObjectToJsonString(Foo);
  finally
    Foo.Free;
  end;
  Foo := TJson.JsonToObject<TFoo>(Memo1.Lines.Text);
  try
    Foo.Fee := 100;
    Memo1.Lines.Add(TJson.ObjectToJsonString(Foo));
  finally
    Foo.Free;
  end;
end;


http://blogs.embarcadero.com/stephenball/2014/06/05/how-to-convert-an-object-to-json-and-back-with-a-single-line-of-code/
Zivota Milic

Posts: 35
Registered: 4/4/08
Re: IniFiles VS JSON  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 5, 2014 1:13 AM   in response to: Eli M in response to: Eli M
Eli M wrote:
Will this work?

uses REST.JSON; // Also new System.JSON
 
procedure TForm1.Button1Click(Sender: TObject);
var
  Foo: TFoo;
begin
  Foo := TFoo.Create;
  try
    Foo.Foo := 'Hello World';
    Foo.Fee := 42;
    Memo1.Lines.Text := TJson.ObjectToJsonString(Foo);
  finally
    Foo.Free;
  end;
  Foo := TJson.JsonToObject<TFoo>(Memo1.Lines.Text);
  try
    Foo.Fee := 100;
    Memo1.Lines.Add(TJson.ObjectToJsonString(Foo));
  finally
    Foo.Free;
  end;
end;


http://blogs.embarcadero.com/stephenball/2014/06/05/how-to-convert-an-object-to-json-and-back-with-a-single-line-of-code/

Hello Eli,

thank you for your answer.

Yes, I know that and I intend to use this procedure, but my question was if i suppose that TFoo class was like this:

TFoo = class
private
FFee : Integer;
FFoo : String;
FLista : TList<TAnotherClass>;
published
property Fee : Integer read FFee write FFee;
property Foo : String read FFoo write FFoo;
property Lista : TList<TAnotherClass> read FLista;
end;

it works?

thank you
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02