2
votes

I want my Delphi FireMonkey application to store all information from the Edit.Text Components anywhere the app can reload these data from another time the app is being started. (it is not neccessary or needed, but I also would like to save some Memo.Text and Combobox.ItemIndex [and maybe some other] data, too.)

The only way I can imagine of is to write a procedure, that stores all information into a TMemo and saves it into a file. (and another procedure to reassign these things) If there were just a few information I´d do this, but I´ve got way too much data to remember so it is too hard to do so.

My question ist how can I make my application remember all these data/values easily. (Something like function SaveAllComponentsValues;) My app will be running on Mac, Windows, iOS and Android so the solution have to work on all these platforms.

I guess it would be possible to store all properties of the [specific / all] components. This would also be very helpful to me.

1
The documentation says "The saving of this state is only "transient"; if you shut down the application manually or from the task manager and then restart it, the previous "transient" state will be lost. " I wantet to store information for the case the application pauses / gets in the background or the device restarts etc. so this is not what I wanted my app to us, but its close to the wanted solution. Thanks - qGold
Well, you should read the complete doc page. It describes both variants ... see 2.2 Storage Location and Name on the doc page. - Sir Rufo
Yes, this worked very well and it was exactly the solution I was waiting for. - qGold

1 Answers

0
votes

If you are sure you shouldn't be using a database then you could use an inifile to hold the values and iterate through the compnents on the form. Don't know anything about mobile so not sure about that but here are 2 procedures that save and restor all the Tedit components on the form:

uses system.ioutils;
..


procedure TForm2.savebuttonClick(Sender: TObject);

var i:integer;
    acomponent:tcomponent;
    inifile:tinifile;

begin
  inifile:=tinifile.Create(tpath.GetHomePath+tpath.DirectorySeparatorChar+'myinifile.ini');
  for i:=0 to form2.ComponentCount-1 do
  begin
    acomponent:=form2.Components[i];
    if acomponent.ClassType=tedit then inifile.WriteString('Edits',acomponent.Name,(acomponent as tedit).Text)
  end;
  inifile.free
end;

procedure TForm2.restorebuttonClick(Sender: TObject);

var i:integer;
    acomponent:tcomponent;
    inifile:tinifile;

begin
  inifile:=tinifile.Create(tpath.GetHomePath+tpath.DirectorySeparatorChar+'myinifile.ini');
  for i:=0 to form2.ComponentCount-1 do
  begin
    acomponent:=form2.Components[i];
    if acomponent.ClassType=tedit then
    begin
      (acomponent as tedit).Text:=inifile.readString('Edits',acomponent.Name,'')
    end;
  end;
  inifile.free
end;