Please can someone help me out on an issue that I ma having with delphi.
Aim is to read an INI file then take certain values only and display them under listbox or memo.
Lets say for an example my ini files looks like this

Device =


Only values I want to read is device, sector and anyname without the ‘=’
I tried with TIniFile and text, what I am getting stuck is how to identify the [setup], [set] and the ‘=’ to ignore and take the next value.
When the files is read it is at the EOF, am I correct!! If this is the case I need to decrement it to the start of the page, then create a condition to compare [setup] , [set] and the =. Then with the condition true, I need to increment by 1 (or delete the char or the string).

My question to you is, how do I decrement and inc, as I get an error with int and string.
Is this the correct approach, or do you recommend a different approach (maybe read the file as a string) as they increment compare the char then remove
Please advice
Thx in adv

7 Years
Discussion Span
Last Post by FlamingClaw

(Assuming the order of the elements will never be changed)

> You could read the file line by line ...
(and every time you put the line into a string)
> Then you only have to scan the string for the character '=' and read out the value after it ...

Hope this helps !


Hi "1shadow1" :)
What about the delphi help?If you search you find.
Use the TIniFile keyword



TIniFile enables handling the storage and retrieval of application-specific information and settings in a standard INI file. The INI file text format is a standard introduced in Windows 3.x for storing and retrieving application settings from session to session. An INI file stores information in logical groupings, called “sections.” For example, the WIN.INI file contains a section called “[Desktop]”. Within each section, actual data values are stored in named keys. Keys take the form:


A FileName is passed to the TIniFile constructor and identifies the INI file that the object accesses.

A related object, TMemIniFile, works the same way as TIniFile, but buffers writes in memory to minimize disk access.

Tip: You may choose to store information using the system registry instead of INI files. In this case, you can use TRegistryIniFile (which shares a common ancestor with TIniFile and so can be used in common code) or TRegistry.


I see,that you want to more....
The ini file format is still popular, many configuration files (such as the DSK Desktop settings file) are in this format. This format is especially useful in cross-platform applications, where you can't always count on a system Registry for storing configuration information. BaseCLX provides two classes, TIniFile and TMemIniFile, to make reading and writing ini files very easy.

TIniFile works directly with the ini file on disk while TMemIniFile buffers all changes in memory and does not write them to disk until you call the UpdateFile method.

When you instantiate the TIniFile or TMemIniFile object, you pass the name of the ini file as a parameter to the constructor. If the file does not exist, it is automatically created. You are then free to read values using the various read methods, such as ReadString, ReadDate, ReadInteger, or ReadBool. Alternatively, if you want to read an entire section of the ini file, you can use the ReadSection method. Similarly, you can write values using methods such as WriteBool, WriteInteger, WriteDate, or WriteString.

Following is an example of reading configuration information from an ini file in a form's OnCreate event handler and writing values in the OnClose event handler.

procedure TForm1.FormCreate(Sender: TObject);
  Ini: TIniFile;
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
    Top     := Ini.ReadInteger( 'Form', 'Top', 100 );
    Left    := Ini.ReadInteger( 'Form', 'Left', 100 );
    Caption := Ini.ReadString( 'Form', 'Caption', 'New Form' );
    if Ini.ReadBool( 'Form', 'InitMax', false ) then
      WindowState = wsMaximized

      WindowState = wsNormal;

procedure TForm1.FormClose(Sender: TObject; var Action TCloseAction)
  Ini: TIniFile;
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
    Ini.WriteInteger( 'Form', 'Top', Top);
    Ini.WriteInteger( 'Form', 'Left', Left);
    Ini.WriteString( 'Form', 'Caption', Caption );
    Ini.WriteBool( 'Form', 'InitMax', WindowState = wsMaximized );


Each of the Read routines takes three parameters. The first parameter identifies the section of the ini file. The second parameter identifies the value you want to read, and the third is a default value in case the section or value doesn't exist in the ini file. Just as the Read methods gracefully handle the case when a section or value does not exist, the Write routines create the section and/or value if they do not exist. The example code creates an ini file the first time it is run that looks like this:

Caption=Default Caption

On subsequent execution of this application, the ini values are read in when the form is created and written back out in the OnClose event.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.