Monday, 18 February 2013

How to Create and Use INI Files in Delphi XE2?

How to Create and Use INI Files in Delphi XE2?

Create an INI file (config.ini) which will have your application configuration settings like database connection settings, log settings, email settings etc. INI file is must for a big delphi application as you need to change various settings for application time to time. If you maintain INI file then you don't have to go in delphi code or database to change the settings everytime, you can just open INI file and make your changes.

Suppose you have created following INI file (config.ini)

ABC = 10
XYZ = 'Hello User'

Now, you have one integer value and one string value in ini. Lets create an delphi function to read this simple ini file.

You will have to use TIniFile delphi component from VCL. Declare object of this component.

IniValues : TIniFile;

procedure TMyForm.ReadINIFilesDelphi;
 ABCValue : Integer;
 XYZValue : String;
    IniValues := TIniFile.Create('config.ini');
    ABCValue := IniValues.ReadInteger('ConfigSettings','ABC',0);
    XYZValue := IniValues.ReadString('ConfigSettings','XYZ','');

    on E : Exception do
      ShowMessage('Error occured in function ReadINIFilesDelphi: ' + E.Message);

Above delphi procedure used ReadInteger and ReadString to read from INI files. It assigns 0 as default value to ABCValue and '' to XYZValue.


  1. Good information and a much needed one.

  2. I can enter a comment here, but...
    How do I enter a comment line into an ini file ??

  3. Burberry Outlet Air Max Shoes Coach Black Friday Coach Black Friday Coach Cyber Monday Coach Factory Coach Outlet Factory Coach Outlet USA Coach Purses Factory Coach Purses USA Coach Store Outlet Coach Purses On Sale Monster Beats Outlet Louis Vuitton Outlet Louis Vuitton Factory Marc Jacobs On Sale MCM Outlet MCM 店铺 cheap oakley sunglasses Michael Kors Outlet Michael Kors Outlet Michael Kors Factory Michael Kors Outlet Michael Kors Factory Online Coach Factory Outlet North Face Outlet Online Polo Outlet Store Ralph Lauren UK Sac Longchamp Pairs Coach Outlet Online Coach Factory Oultet Barbour Jackets Outlet Online Canada Goose Outlet Gucci Outlet Online Michael Kors Outlet Moncler Clearance Moncler Jackets Outlet Online North Clearace Outlet Polo Ralph Lauren Outlet Online Woolrich Clearance Michael Kors Factory Outlet Coach Outlet Online USA Beats by Dre Coach Purses Outlet Online Michael Kors USA