SunQuest
 
       Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 4 - Working with INI Files in Delphi
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Working with INI Files in Delphi
By: Danish Ahmed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-09-04

    Table of Contents:
  • Working with INI Files in Delphi
  • TIniFile and TMemIniFile Classes
  • Working with Sections
  • TRegistryIniFile Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Working with INI Files in Delphi - TRegistryIniFile Class


    (Page 4 of 4 )

    One of the reasons why INI files are still in use is the fact that they are easier and safer to approach than messing with the Registry and the fact that the system Registry is specific to Windows only. But it is also a fact that Windows Registry, which stores data in a hierarchical form and doesn't have a size limit, is more suited to present times. Delphi eases the transition from INI files to Registry or writing cross platform applications intended for both Windows and Linux systems by providing the TRegistryIniFile class. This class inherits all the of methods and properties of TCustomIniFile and can be used to read and write to the Registry in the same manner as writing to the INI file. In fact, the same code can be used to write to both an INI file and Windows Registry by adding a conditional in the code to provide an instance of TRegistryIniFile when it is running Windows and TMemIniFile when it is running Linux.

    For instance, if the parameter you provide in the constructor of the TIniFile class results in the creation of an INI file of the same name, substituting it with TRegistryIniFile would make it create a subkey in the Registry's root key (eg HKEY_CURRENT_USER). The section of the INI file corresponds to the key in the system Registry and the key/value correspond to data values under the key. So if I were to modify the above code to instantiate TRegistryIniFile instead of the TIniFile class I don't have to code the entire block once more.

    var
    myIniFile:TRegistryIniFile;
    begin
    myIniFile:=TRegistryIniFile.Create('TestIni');
    try
    myIniFile.WriteString('TestCompanyInfo','CompanyName','mindfire');
    finally
    myIniFile.Free;
    end;
    end;

    If you are porting an existing application to use Registry instead of INI files or are writing a cross-platform application, this approach can help you avoid writing that extra bit of code. If you want the ease of INI files and robustness of the Windows Registry without needing to write extra code, TRegistryIniFile class is what you need to use.

    Danish Ahmed
    Mindfire Solutions


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    DELPHI-KYLIX ARTICLES

    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...
    - Using Try and Finally to Help Prevent Memory...
    - The Implementation of an FTP Server
    - FTP Server: The Theory







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway