The TIniFile class (from System.IniFiles) provides a simple way to manage configuration settings in the classic INI format.
| Name | Parameters | Description |
|---|---|---|
Create |
fileName |
Initializes from a file on disk. |
CreateInMemory |
content |
Initializes from a string containing INI data. |
| 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. |
Changes are automatically flushed to disk when the TIniFile instance is freed. There is no explicit UpdateFile method.
| Property | Type | Description |
|---|---|---|
Encoding |
String |
The text encoding used for the file (e.g. 'utf-8'). |
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; The DWScript implementation of TIniFile primarily handles string values. To read other types, use conversion functions: StrToInt(ini.ReadString(...)) or StrToBool(ini.ReadString(...)).