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)

[ConfigSettings]
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;
var
 ABCValue : Integer;
 XYZValue : String;
begin
  try
    IniValues := TIniFile.Create('config.ini');
   
    ABCValue := IniValues.ReadInteger('ConfigSettings','ABC',0);
    XYZValue := IniValues.ReadString('ConfigSettings','XYZ','');


    IniValues.Free;
  except
    on E : Exception do
    begin
      ShowMessage('Error occured in function ReadINIFilesDelphi: ' + E.Message);
    end;
  end;
end;


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

3 comments:

  1. Good information and a much needed one.

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

    ReplyDelete
  3. http://www.burbagssale2013.com/ Burberry Outlet
    http://www.airmaxshoesfactory.com/ Air Max Shoes
    http://www.coachblackfriday2014.com/ Coach Black Friday
    http://www.coach-storeoutletonline.com/ Coach Black Friday
    http://www.coachcoachoutlet.com/ Coach Cyber Monday
    http://www.coachxfactory.com/ Coach Factory
    http://www.coach-factoryoutletonline.net/ Coach Outlet Factory
    http://www.coach-outletonlineusa.com/ Coach Outlet USA
    http://www.coach-pursesfactory.com/ Coach Purses Factory
    http://www.coachpurseusa.com/ Coach Purses USA
    http://www.coach-storeoutlet.com/ Coach Store Outlet
    http://www.coach-pursesonline.com/ Coach Purses On Sale
    http://www.monsterbeatsbydres.com/ Monster Beats Outlet
    http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet
    http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory
    http://www.marcjacobsonsale.com/ Marc Jacobs On Sale
    http://www.mcmworldwides.com/ MCM Outlet
    http://www.mcmoutlet-jp.com/ MCM 店铺
    http://www.oakleysunglassesfactory.com/ cheap oakley sunglasses
    http://www.michaelkorsmas.com/ Michael Kors Outlet
    http://www.michaelkors.so/ Michael Kors Outlet
    http://www.michaelkorsfactory-store.com/ Michael Kors Factory
    http://www.michaelkorsoutletr.com/ Michael Kors Outlet
    http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online
    http://www.newcoachfactoryoutlet.com/ Coach Factory Outlet
    http://www.north-faceoutletonlines.net/ North Face Outlet Online
    http://www.polo-outletstore.com/ Polo Outlet Store
    http://www.ralph-laurenhome.com/ Ralph Lauren UK
    http://www.saclongchamppairs.com/ Sac Longchamp Pairs
    http://www.tcoachoutletonline.com/ Coach Outlet Online
    http://www.the-coachfactoryoutlet.com/ Coach Factory Oultet
    http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online
    http://www.canada-gooser.com/ Canada Goose Outlet
    http://www.guccishoesuk-2014.com/ Gucci Outlet Online
    http://www.michaelkorsstates.com/ Michael Kors Outlet
    http://www.moncler-clearance.com/ Moncler Clearance
    http://www.famousbagsmall.com/
    http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online
    http://www.northsclearance.com/ North Clearace Outlet
    http://www.polo-ralphlaurenonline.com/ Polo Ralph Lauren Outlet Online
    http://www.woolrich-clearance.com/ Woolrich Clearance
    http://www.cvshopfactory.com/ shop.coachfactory.com
    http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet
    http://www.zxcoachoutlet.com/ Coach Outlet Online USA
    http://www.thebeatsbydre.net/ Beats by Dre
    http://www.vipbagsmall.com/
    http://www.newoutletonlinemall.com/ Coach Purses Outlet Online
    http://www.clickmichaelkors.com/ Michael Kors USA

    ReplyDelete