Saving form data to an inifile

Hello,
How would you save form information to an infile. For example if a checkbox was checked by a user or a menu item was checked.When the program is restarted the above conditions are restored into the form by reading a inifile.
frwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

classmateCommented:
Use a TIniFile object to create and access an Inifile.

Further answer depends on how automatic you want the functionality to be. If it's possible to define a limited collection of properties to save and load, you can define an ID for each of them.

Classmate.
0
classmateCommented:
Use e.g. TCustomIniFile.WriteBool to save the TCheckBox.Checked property.

Example:
  MyIniFile.WriteBool ('FormProperties', CheckBox1.Name, MyCheckBox.Checked);

This saves the value of MyCheckBox.Checked under the section 'FormProperties' at the ident CheckBox1.Name.

In e.g. your OnShow or onCreate event handlers of your form, write a corresponding ReadBool call.


classmate.
0
classmateCommented:
Sorry, CheckBox1=MyCheckBox.... :-(
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

intheCommented:
Hi
well this example is for showing a splasscreen on startup if a checkbox is checked but principal is the same:

uses inifiles;

TForm1 = class(TForm)
CheckBox1: TCheckBox;
{etc.}
private
IniFile: TIniFile;
ShowSplash: boolean;
end;
 
procedure FormCreate(Sender: TObject);
begin
IniFile:=TIniFile.Create('c:\MyFile.ini');
ShowSplash := IniFile.ReadBool('Splash', 'Show', True);
CheckBox1.Checked := ShowSplash;
if ShowSplash then
  SplashForm := TSplashForm.Create(Application);
end;
 
procedure FormClose(Sender: TObject);
begin
ShowSplash := CheckBox1.Checked;
IniFile.WriteBool('Splash', 'Show', ShowSplash);
IniFile.Free
end;
 
end.
 


it is probably beter nowadays to use the registry to save these settings.
if you need i can give an example of saving the forms settings to the registry instead.
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
sorry classmate posted without pressing refresh :-(
0
frwAuthor Commented:
Could you send me the Registry example.
Thankyou.
batt@netrover.com
0
intheCommented:
ok cheers,
have emailed a demo of saving the settings in the registry.
Regards Barry
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.