Board index » delphi » Saving configuration options in an application

Saving configuration options in an application

I have a simple two unit application.  The main unit calls a dialog (unit2
- lets say configuration options) to collect user input.  The information
that I collect I want to save for the next time the program is run.  I also
want that information available in the main unit.  What is the best
strategy for doing this?  Is it generally recommended to use the system
registry or some other method?
--
Rick Cromer
r-cro...@ti.com
http://www.flash.net/~rcromer
http://www-tmg.tig.ti.com/  (Intranet server)

 

Re:Saving configuration options in an application


Rick,
  I would suggest you look at creating an *.ini file for your application
using the TIniFile object.  I've found it to work very well.  If you want
it to be in the same directory as your app the use the following in the
create (ParamStr(0) gives the full path of your exe when it is run):

var
  IniFile: TIniFile;

begin
  try
    IniFile := TInifile.Create(ExtractFilePath(ParamStr(0)) + MyIni.ini);
    {Read or write to ini}
  finally
    IniFile.Free;
  end;
end;

if you want the ini file to be placed in the windows directory (a normal
practice if you are worried about the user moving the app around) then just
provide the *.ini file name with no path and it will automatically be put
there.  E.g.:

IniFile := TInifile.Create(MyIni.ini);      {This will put MyIni in the
windows dir}

Hope this helps!
--
Rod Geraghty (:>)
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Rick Cromer <r-cro...@ti.com> wrote in article
<01bc2428$092bf9e0$472a1...@cromer.itg.ti.com>...

Quote
> I have a simple two unit application.  The main unit calls a dialog
(unit2
> - lets say configuration options) to collect user input.  The information
> that I collect I want to save for the next time the program is run.  I
also
> want that information available in the main unit.  What is the best
> strategy for doing this?  Is it generally recommended to use the system
> registry or some other method?
> --
> Rick Cromer
> r-cro...@ti.com
> http://www.flash.net/~rcromer
> http://www-tmg.tig.ti.com/  (Intranet server)

Other Threads