delphi - Load/Save .ini file -
i wrote code let's me save variables .ini file custom filename. filename depends on text in editbox1. no problem there. issue how load variables custom filename selecting file load file window (windows explorer).
dataini:=tinifile.create(getcurrentdir+'\save folder\' + editbox1.text +'.ini');
sample save variable
dataini.writestring('info','firstname',editfirstname.text); dataini.writestring('info','middlename',editmiddlename.text); dataini.writestring('info','familyname',editfamilyname.text);
sample load variable
editfirstname.text := dataini.readstring('info','firstname',editfirstname.text); editmiddlename.text := dataini.readstring('info','middlename',editmiddlename.text); editfamilyname.text := dataini.readstring('info','familyname',editfamilyname.text);
so example editbox1.text = 'myfile1', how load variables saved in myfile1.ini selecting myfile1.ini list of other files?
you can use topendialog
name of file want, call function load values.
uses inifiles; ...
on click button, call opendialog.execute allows select file name.
procedure tform1.button1click(sender: tobject); begin topendialog.create(self) try filter := 'ini files (*.ini)|*.ini'; if execute loadmyvars(filename); free; end; end;
this function load values of ini file controls.
procedure tform1.loadmyvars(const afilename: string); var dataini : tinifile; begin dataini := tinifile.create(afilename); try editfirstname.text := dataini.readstring('info','firstname', ''); editmiddlename.text := dataini.readstring('info','middlename', ''); editfamilyname.text := dataini.readstring('info','familyname', ''); freeandnil(dataini); end; end;
Comments
Post a Comment