TIniFile

Navigation:  Les scripts > Les autres scripts > Procedure and function > Specifics > Objects >

TIniFile

Previous pageReturn to chapter overviewNext page

TIniFile object

 

TIniFile enables handling the storage and retrieval of application-specific information and settings in a Windows 3.x INI file. The INI file text format is the standard way for Windows 3.x applications to store and retrieve 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:

 

<keyname>=<value>

 

The FileName passed to a TIniFile object when it is created is the name of the INI file the object accesses.

 

Note:        Under 32-bit Windows systems, applications typically replace INI files with the system registry where all applications store and retrieve their settings. Delphi provides additional classes for handling the system registry. TRegistry encapsulates the system registry. TRegistryIniFile also encapsulates the registry, but shares a common ancestor with TIniFile so that the same code can access entries stored in either format.

 

Tinifile.IniCreate Constructor

 

Creates a TIniFile object for an application.

 

Constructor IniCreate(const FileName String);

 

IniCreate constructs a TIniFile object for an application. IniCreate inherits Create from TObject, and creates an additional property, FileName, which is used to specify the name of the INI file to use.

 

Note:        Usually INI files are stored in the \WINDOWS directory. To work with an INI file in another location, specify the full path name of the file in FileName.

 

Tinitfile.IniFree method

Procedure Inifree;

 

Use IniFree to destroy an object. IniFree automatically calls the destructor if the object reference is not nil. Any object instantiated at runtime that does not have an Owner should be destroyed by a call to Free, so that can be properly destroyed and the memory released. Unlike Destroy, Free is successful even if the object is nil, so if the object was never initialized, Free won’t result in an error.

 

Tinifile.IniReadString method

 

function IniReadString(const Section, Ident, Default: string): string;

 

Call ReadString to read a string value from an INI file. Section identifies the section in the file that contains the desired key. Ident is the name of the key from which to retrieve the value. Default is the string value to return if the:

 

Section does not exist.

Key does not exist.

Data value for the key is not assigned.

 

Tinifile.IniWriteString method

 

Writes a string value to an INI file.

 

procedure IniWriteString(const Section, Ident, Value: string);

 

Call IniWriteString to write a string value to an INI file. Section identifies the section in the file that contain the key to which to write. Ident is the name of the key for which to set a value. Value is the string value to write.

 

Note:        Attempting to write a data value to a non-existent section or attempting to write data to a non-existent key are not errors. In these cases, WriteString creates the section and key and sets its initial value to Value.

 

Tinifile.IniReadBool method

 

Retrieves a Boolean value from an INI file.

 

function IniReadBool (const Section, Ident: String; Default: Boolean): Boolean;

 

Call IniReadBool to read a Boolean value from an INI file. Section identifies the section in the file that contains the desired key. Ident is the name of the key from which to retrieve the Boolean value. Default is the Boolean value to return if the:

 

Section does not exist.

Key does not exist.

Data value for the key is not assigned.

 

TiniFile.IniWriteBool method

 

Writes a Boolean value to an INI file.

 

procedure IniWriteBool(const Section, Ident: String; Value: Boolean);

 

Call IniWriteBool to write a Boolean value to an INI file. Section identifies the section in the file that contain the key to which to write. Ident is the name of the key for which to set a value. Value is the Boolean value to write.

 

Note:        Attempting to write a data value to a non-existent section or attempting to write data to a non-existent key are not errors. In these cases, WriteBool creates the section and key and sets its initial value to Value.

 

Tinifile.IniReadInteger method

 

Retrieves an integer value from an INI file.

 

function IniReadInteger(const Section, Ident: String; Default: Longint): Longint;

 

Call IniReadInteger to read an integer value from an INI file. Section identifies the section in the file that contains the desired key. Ident is the name of the key from which to retrieve the value. Default is the integer value to return if the:

 

Section does not exist.

Key does not exist.

Data value for the key is not assigned.

TiniFile.IniWriteFloat method

 

Writes a float value to an INI file.

 

procedure IniWriteFloat(const Section, Ident: String; Value: Double); virtual;

 

Call IniWriteFloat to write a float value to an INI file. Section identifies the section in the file that contain the key to which to write. Ident is the name of the key for which to set a value. Value is the float value to write.

 

Note:        Attempting to write a data value to a non-existent section or attempting to write data to a non-existent key are not errors. In these cases, WriteFloat creates the section and key and sets its initial value to Value.

 

Tinifile.IniReadFloat method

 

Retrieves a float value from an INI file.

 

function IniReadFloat (const Section, Ident: String; Default: Double): Double; virtual;

 

 

Call ReadFloat to read a float value from an INI file. Section identifies the section in the file that contains the desired key. Ident is the name of the key from which to retrieve the float value. Default is the float value to return if the:

 

Section does not exist.

Key does not exist.

Data value for the key is not assigned.

 

Tinifile.IniSectionExist method

 

Indicates whether a section exists in the INI file.

 

function IniSectionExist (const Section: String): Boolean;

 

Use IniSectionExist to determine whether a section exists within the INI file specified in FileName.

 

Section is the INI file section IniSectionExist determines the existence of.

 

IniSectionExist returns a Boolean value that indicates whether the section in question exists.

 

Tinifile.IniEraseSection method

 

Erases an entire section of an INI file.

 

procedure IniEraseSection(const Section: string);

 

Call IniEraseSection to remove a section, all its keys, and their data values from an INI file. Section identifies the INI file section to remove. If a section cannot be removed, an exception is raised.