Home arrow Delphi-Kylix arrow Page 4 - Working with INI Files in Delphi
DELPHI-KYLIX

Working with INI Files in Delphi


Microsoft has taken steps to phase out .ini or initialization files, but they are too useful in too many situations to completely disappear just yet. For example, there are specific cases where you would want to use an INI file when developing a cross-platform application. This article explains how to create and use an INI file in Delphi.

Author Info:
By: Danish Ahmed
Rating: 5 stars5 stars5 stars5 stars5 stars / 25
September 04, 2007
TABLE OF CONTENTS:
  1. · Working with INI Files in Delphi
  2. · TIniFile and TMemIniFile Classes
  3. · Working with Sections
  4. · TRegistryIniFile Class

print this article
SEARCH DEVARTICLES

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.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials