Overview

Configuration (INI)

The TIniFile class (from System.IniFiles) provides a simple way to manage configuration settings in the classic INI format.

TIniFile Class

Constructors

Name Parameters Description
Create fileName Initializes from a file on disk.
CreateInMemory content Initializes from a string containing INI data.

Methods

Method Parameters Description
ReadString section, name, default Reads a string value.
WriteString section, name, value Writes a string value.
ReadSections Returns array of String with all section names.
ReadSectionNames section Returns array of String with all keys in a section.
EraseSection section Removes an entire section.
DeleteKey section, name Removes a specific key.
FileName Returns the path to the associated INI file.
ToString Returns the entire INI content as a string.

Auto-Save

Changes are automatically flushed to disk when the TIniFile instance is freed. There is no explicit UpdateFile method.

Properties

Property Type Description
Encoding String The text encoding used for the file (e.g. 'utf-8').

Example: Basic Operations

uses System.IniFiles;

var ini := new TIniFile('.data/config.ini');
try
  ini.WriteString('Database', 'User', 'admin');
  ini.WriteString('Database', 'Pass', 'secret');
finally
  ini.Free; // Flushes to disk
end;

Typing Note

The DWScript implementation of TIniFile primarily handles string values. To read other types, use conversion functions: StrToInt(ini.ReadString(...)) or StrToBool(ini.ReadString(...)).

On this page