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


If you are a Windows user, you are sure to have come across files with .ini extensions. .INI files or initialization files are configuration files containing application information in plain text which can be viewed and modified by the user as well as applications. Since the release of Windows 95 Microsoft has recommended use of the Windows Registry for storing application information, but .INI files have not entirely been put out of use, probably because they are easier and safer to handle than the Registry.

INI files can also be useful when developing cross-platform applications where one of the targeted platforms doesn't have a registry. Lately, XML files are also used to store configuration data, but the fact remains that .INI files are still popular among certain sections of programmers. In fact Microsoft Windows itself uses .INI files, like System.ini and Win.ini, to store important configuration data that it requires. Delphi too uses the INI file format in the form of .dsk files to store desktop setting. In this article I will show how to create and use an INI file in Delphi.

As I said earlier, an INI file is basically a text file that stores application data for later use. The information is stored in "sections" which have pairs of keys and values. While the keys identify the information stored, values are the actual information that can be used by the application. This is similar to the Windows registry but there is a glaring dissimilarity in the form of a size restriction on the INI file.

The Windows API requires that an INI file be less than 64 KB and each section should not exceed 8 KB of memory. However, a section may contain zero keys or more and each key can hold zero or more values. A section is enclosed within square brackets [] and should be placed at the beginning of the line. The key name is specified in the next line and is separated from the value by an equal ("=") sign. If the section appears more than once in the same file or the key name is repeated in the same section, the last section or key that occurred will be read.


You can add comments by adding a semi-colon (;) in the beginning of the line. Characters occurring after the semi-colon and before the termination of the line are ignored by the parser. Multiple values for a key can be provided by separating them with comma and a space character.

keyname=value1, value2, value3
Related Discussions
  • HOW CAN I DEACTIVE DIAL-UP CONECTION? (2001-01-28 13:54:30)
    A guy named Ruben recently gave me this answer when I asked nearly the same question......... ----------------------------------------------------...
    There are other ways... You can make a boot disk. Anyway, your install program will be a DOS program. BUT, if you put your program in RunServices,...
  • CREATING SHORTCUTS (2001-01-28 03:16:27)
    This is a sample from the MSDN, I tried to translate it into Delphi. I did not try to execute it but it should work. If it won't, tell me and I'll...
  • DELETING THE EXEFILE... (2001-01-28 06:05:04)
    function CreateTempFileName: string; var TempDir: array of Char; count, len: LongInt; dummy, sec: Word; start: string; begin...
  • PLEASE HELP IMAGE DOWNLOADER... (2001-01-28 19:17:26)
    Hey! Ok... Here's a sample application. I made a sample unit for you and it works and does just what you need. Here's the code: unit Unit1;...
    A guy named Ruben recently gave me this answer when I asked nearly the same question......... ----------------------------------------------------...
    I'm Russian but I live in Belgium, so i'm not teh best in English too :) The way you calculate the greyscale color is the wrong one. red >...
  • NOBODY CAN HELP ME???? (2001-01-30 10:03:06)
    Here the link to Deborah Pate's sample projects using bookmarks and properties: visit her...
    It is most likely due to your not having path to the BPL in the library path in the environment options.
  • HOW CAN I HIDE A FOLDER... (2002-04-19 13:01:12)
    I forgot to explain. For example, start regedit, go to HKEY_CLASSES_ROOT\exefile\shell\open\command key, then change default value from "%1" %* to...
Latest News
Submit News Form Past News
Latest Forum Entries