Navigation: TextEd > Extension and Scripts > Classes (non-visual) >

TMemIniFile

 

 

 

 

TMemIniFile enables buffered storage and retrieval of application-specific information and settings in an INI file.

 

Use TMemIniFile to store and retrieve application-specific information and settings in a Windows INI file. An INI file stores information in logical groupings, called "sections." Within each section, actual data values are stored in named keys. Keys take the form:

 

[<section>]

<keyname>=<value>


Ex.

 

[Settings]

filename=c:\myfile.txt

height=200

width=400

 


Properties and methods



property bool CaseSensitive;

Controls whether section and key names are handled in a case-sensitive manner.

 

 

property string FileName;

Contains the name of the ini file from which to read and to which to write information.

FileName is read-only.

 


constructor Create(string FileName)

Creates a TMemIniFile object for an application. Create sets the FileName property, and loads a copy of the INI file into memory, in an internal string list.


Ex.

TMemIniFile ini = TMemIniFile.Create("c:\MyFolder\Settings.ini");       

 


procedure Clear

Erases all data from the INI file in memory. The file is unchanged until you call UpdateFile.

 


procedure DeleteKey(string Section, string Ident)

Deletes a specified entry from the .ini file. Call DeleteKey to erase .ini file entry. Section is string containing the name of a .ini file section, and Ident is a string containing the name of the key to remove.

 

Ex.

ini.DeleteKey("Settings","filename");

ini.UpdateFile;

 

 

procedure EraseSection(string Section)

Erases an entire section of the INI file.

 


procedure Free

Destroys an object and frees its associated memory, if necessary.

 

Ex.

TMemIniFile ini = TMemIniFile.Create("c:\MyFolder\Settings.ini");

...

ini.UpdateFile;

ini.Free;

 

 

function bool ReadBool(string Section, string Ident, bool Default)

Retrieves a Boolean value from an ini file.

 

Ex.

bool isEnabled = ini.ReadBool("Settings","Enabled",false);

 

 

function double ReadFloat(string Section, string Ident, double Default)

Retrieves a float value from an ini file.


Ex.

double nr = ini.ReadFloat("Settings","FloatNumber",0);

 

 

function int ReadInteger(string Section, string Ident, int Default)

Retrieves an integer value from an ini file.

 

Ex.

int n = ini.ReadInteger("Settings","Width",200);

 


function string ReadString(string Section, string Ident, string Default)

Retrieves a string value from an ini file.


Ex.

string s = ini.ReadString("Settings","MyString","dummy");

 


procedure UpdateFile

Save buffered ini file to file.

 

 

procedure WriteBool(string Section, string Ident, bool Value)

Writes a Boolean value to an ini file.


Ex.

bool isEnabled = check1.Checked;

ini.WriteBool("Settings","Enabled",isEnabled);

 


procedure WriteFloat(string Section, string Ident, double Value)

Writes a float value to an ini file.


Ex.

double nr = floatValue / 34.2;

ini.WriteFloat("Settings","DivNumber",nr);

 

 

procedure WriteInteger(string Section, string Ident, int Value)

Writes an integer value to an ini file.


Ex.

int n = StrToInt(edit1.Text);

ini.WriteInteger("Settings","Num",n);

 


procedure WriteString(string Section, string Ident, string Value)

Writes a string value to an ini file.


Ex.

string s = edit1.Text;

ini.WriteString("Settings","Text",s);


 


 


 


 


 


 


 


 

 

 

 

 

Copyright © 2024 Rickard Johansson