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.
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.
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.