PDA

View Full Version : nobie question - how to save



scratch
20-03-2005, 12:56 AM
i have 2 groupbox's in form1, and in both i have like 5 checkbox's.i also have a button called btnSave and another called btnLoad. my question is, how can i make it so when i click btnSave, the staus of all the checkbox's (whether they are checked or not) is saved to a file. and when i press btnLoad, they are loaded.
hope i made myself clear. :?
i really need an answer for this urgently. :(
thanks in advance. :D

Paulius
20-03-2005, 08:00 AM
Wheather checkboxs are checked is represented by their boolean property Checked, so all you need is save and load them.

M109uk
20-03-2005, 01:22 PM
Hi,

you could use an ini file to store the propertise:


uses
IniFiles;

procedure LoadFromFile;
var
Ini: TIniFile;
begin
Ini := TIniFile.Create('MyInifile.ini');

// Read a boolean variable from ini, section 'Group1' default values is true.
CheckBox1.Checked := Ini.ReadBoolean('Group1', 'Checkbox1', True);
CheckBox2.Checked := Ini.ReadBoolean('Group1', 'Checkbox2', True);
CheckBox3.Checked := Ini.ReadBoolean('Group1', 'Checkbox3', True);
CheckBox4.Checked := Ini.ReadBoolean('Group1', 'Checkbox4', True);
CheckBox5.Checked := Ini.ReadBoolean('Group1', 'Checkbox5', True);

// Read a boolean variable from ini, section 'Group2' default values is true.
CheckBox6.Checked := Ini.ReadBoolean('Group2', 'Checkbox6', True);
CheckBox7.Checked := Ini.ReadBoolean('Group2', 'Checkbox7', True);
CheckBox8.Checked := Ini.ReadBoolean('Group2', 'Checkbox8', True);
CheckBox9.Checked := Ini.ReadBoolean('Group2', 'Checkbox9', True);
CheckBox10.Checked := Ini.ReadBoolean('Group2', 'Checkbox10', True);

Ini.Free;
end;

procedure SaveToFile;
var
Ini: TIniFile;
begin
Ini := TIniFile.Create('MyInifile.ini');

// Read a boolean variable from ini, section 'Group1' default values is true.
Ini.WriteBoolean('Group1', 'Checkbox1', CheckBox1.Checked);
Ini.WriteBoolean('Group1', 'Checkbox2', CheckBox2.Checked);
Ini.WriteBoolean('Group1', 'Checkbox3', CheckBox3.Checked);
Ini.WriteBoolean('Group1', 'Checkbox4', CheckBox4.Checked);
Ini.WriteBoolean('Group1', 'Checkbox5', CheckBox5.Checked);

// Read a boolean variable from ini, section 'Group2' default values is true.
Ini.WriteBoolean('Group2', 'Checkbox6', CheckBox6.Checked);
Ini.WriteBoolean('Group2', 'Checkbox7', CheckBox7.Checked);
Ini.WriteBoolean('Group2', 'Checkbox8', CheckBox8.Checked);
Ini.WriteBoolean('Group2', 'Checkbox9', CheckBox9.Checked);
Ini.WriteBoolean('Group2', 'Checkbox10', CheckBox10.Checked);

Ini.Free;
end;

Hope this helps..