Forum > General

How store configuration of form elements (editbox, checkboxes) in files ?

(1/1)

seba22:
Welcome,

How is the best way to store configuration of form elements like "checkboxes nad editboxes" ?

Few years ago ind elphi i was using .ini files .

Is there any easy way, what will work on any systems ?

For example i have:



--- Code: ---[editbox1]

[editbox2]

[editbox3]

[checkbox1]

[checkbox2]

[checkbox3]

[button save]
[button load]
--- End code ---

If user click save, it should save this configuration into file, when i click load it should get value from file ?

Is there easiest way from using ini files ?

I remember it was difficult, and i spend many time to get it working.
maybe there is a better way ?

Regards

exdatis:
TiniFiles! Quite simple.
var
  my_ini : TiniFile;
...
  if FileExists(file_name) then
  begin
    my_ini:=TIniFile.Create(file_name);
    {create string_list}
    my_obj:=TStringList.Create;
    my_ini.ReadSections(my_ob);
...
   also
     my_ini.ReadString('section','item','default_value');
   and
     my_ini.WriteString('section','item','new_value'); 

seba22:
nono my friend!

I wan't be more powerfull.

I found that i should use XMLConfig.

I found how to write and read values like "editbox".

for example, when i want write and read.


--- Code: ---procedure TForm2.Button1Click(Sender: TObject);
begin
  form1.XMLConfig.SetValue('bla',
                       edit1.text);
                       form1.XMLCONFIG.Flush;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
     edit1.texT:=form1.XMLConfig.GetValue('bla', 'defayult vaLUE');
end;
--- End code ---



But i have problem, i add another lines into my test code.
Now i want use checkbox.

--- Code: ---procedure TForm2.Button1Click(Sender: TObject);
begin
  form1.XMLConfig.SetValue('bla',
                       edit1.text);
     form1.XMLConfig.SetValue('checkbox1',
                       checkbox1.checked);


                       form1.XMLCONFIG.Flush;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
     edit1.texT:=form1.XMLConfig.GetValue('bla', '21');
     checkbox1.checked:=form1.XMLConfig.GetValue('checkbox1', 'False');
end;
--- End code ---

It write configuration OK,  i have inside xml  position called 'checkbox1' and value "True".
But when i want read i got error.

this line:

--- Code: ---  checkbox1.checked:=form1.XMLConfig.GetValue('checkbox1', 'False');
unit2.pas(52,71) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "Boolean"

--- End code ---

I understand the error, but maybye its possible to convert that ansi string to boolean ?
if string = true then bolean = true if string = false then bolean = false ?


Regards


seba22:
Is was my bad.

 
--- Code: --- checkbox1.checked:=form1.XMLConfig.GetValue('checkbox1', False);
--- End code ---

False, should not be in quote.
i forgot that, looking at this text file; )


Working great.
Its make me very happy ;)

Regards

Leledumbo:
Drop any of TIniPropStorage or TXMLPropStorage to your form and set what values do you need to store in form's SessionProperties property in object inspector. Done (no coding AT ALL).

Navigation

[0] Message Index

Go to full version