Class TConfigurationFile

Unit

Declaration

type TConfigurationFile = class(TObject)

Description

Handles configuration files.

It gets values from a configuration file, which uses the INI file format, and also from command line options.

Hierarchy

  • TObject
  • TConfigurationFile

Overview

Methods

Public constructor Create; virtual;
Public destructor Destroy; override;
Public procedure Load;
Public function GetValue (const aSection, aKey, aDefault: AnsiString): String;
Public function GetIntValue ( const aSection, aKey: AnsiString; aDefault: Integer ): Integer;
Public function GetBoolValue ( const aSection, aKey: AnsiString; aDefault: Boolean ): Boolean;
Public procedure SetValue (const aSection, aKey, aValue: AnsiString);
Public procedure SetIntValue (const aSection, aKey: AnsiString; aValue: Integer);
Public procedure SetBoolValue (const aSection, aKey: AnsiString; aValue: Boolean);
Public procedure Save;

Properties

Public property FileName: AnsiString read fFileName write fFileName;

Description

Methods

Public constructor Create; virtual;

Constructor.

Note you must call method Load to actually load the configuration file.

See also
TConfigurationFile.FileName
Configuration file name, including path.
TConfigurationFile.Load
(Re)loads configuration file.
Public destructor Destroy; override;

Destructor.

Note that changes in the configuration file won't be saved. You must call Save to do it.

See also
TConfigurationFile.Save
Save current configuration to file.
Public procedure Load;

(Re)loads configuration file.

See also
TConfigurationFile.FileName
Configuration file name, including path.
Public function GetValue (const aSection, aKey, aDefault: AnsiString): String;

Get a configuration value.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aDefault
Default value returned if the key doesn't exist in file.
Returns

The value of the key, or Default if it doesn't exists. Note that if the key exists, but is empty, an empty string will be returned.

See also
TConfigurationFile.SetValue
Set a configuration value.
TConfigurationFile.GetBoolValue
Get a boolean configuration value.
TConfigurationFile.GetIntValue
Get an integer configuration value.
Public function GetIntValue ( const aSection, aKey: AnsiString; aDefault: Integer ): Integer;

Get an integer configuration value.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aDefault
Default value returned if the key doesn't exist in file.
See also
TConfigurationFile.SetIntValue
Set an integer configuration value.
TConfigurationFile.GetValue
Get a configuration value.
Public function GetBoolValue ( const aSection, aKey: AnsiString; aDefault: Boolean ): Boolean;

Get a boolean configuration value.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aDefault
Default value returned if the key doesn't exist in file.
See also
TConfigurationFile.SetBoolValue
Set a boolean configuration value.
TConfigurationFile.GetValue
Get a configuration value.
Public procedure SetValue (const aSection, aKey, aValue: AnsiString);

Set a configuration value.

This method doesn't save the new value to the file. You must call Save for this.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aValue
The new value.
See also
TConfigurationFile.Save
Save current configuration to file.
TConfigurationFile.GetValue
Get a configuration value.
TConfigurationFile.SetBoolValue
Set a boolean configuration value.
TConfigurationFile.SetIntValue
Set an integer configuration value.
Public procedure SetIntValue (const aSection, aKey: AnsiString; aValue: Integer);

Set an integer configuration value.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aValue
The new value.
See also
TConfigurationFile.GetIntValue
Get an integer configuration value.
TConfigurationFile.SetValue
Set a configuration value.
Public procedure SetBoolValue (const aSection, aKey: AnsiString; aValue: Boolean);

Set a boolean configuration value.

Parameters
aSection
Section name. It can be an empty string for the global section.
aKey
Key name.
aValue
The new value.
See also
TConfigurationFile.GetBoolValue
Get a boolean configuration value.
TConfigurationFile.SetValue
Set a configuration value.
Public procedure Save;

Save current configuration to file.

See also
TConfigurationFile.SetValue
Set a configuration value.
TConfigurationFile.FileName
Configuration file name, including path.

Properties

Public property FileName: AnsiString read fFileName write fFileName;

Configuration file name, including path.

Default is GetAppConfigFile (False, False).

Note that assign this property will load the file if it exists.

See also
TConfigurationFile.Load
(Re)loads configuration file.
TConfigurationFile.Save
Save current configuration to file.

Generated by PasDoc 0.15.0. Generated on 2025-07-31 11:41:01.