B4A Class TIniFile - INI file handler class

Hi,

This is a class for handling Configuration Settings (INI) file like in MS Windows. I follow Delphi's names. Perhaps anyone comes from Delphi/Lazarus like me want to use TIniFile in B4A.

It is a simple code, but it's just enough for my current need. You may use, modify, or distribute anyway you want. If would be great if you inform me for any enhancement.


Cheers,
 

Attachments

Public Methods

Initialize
It is for initializing the object.

Declaration
Code: Copy
Sub Initialize(prmDirName As String, prmFileName As String)

Example
Code: Copy
Dim Ini As TIniFile
Ini.Initialize(File.DirInternal, "appname.ini")

GetDirName
Get directory name of the INI file.

Declaration
Code: Copy
Sub GetDirName As String
Example
Code: Copy
Dim IniDirName As String = Ini.GetDirName

GetFileName
Get file name of the INI file.

Declaration
Code: Copy
Sub GetFileName As String
Example
Code: Copy
Dim IniFileName As String = Ini.GetFileName

GetAutoFlush
Get property AutoFlush.

Declaration
Code: Copy
Sub GetAutoFlush As Boolean

Example
Code: Copy
Dim IniAutoFile As Boolean = Ini.GetAutoFlush

SetAutoFlush
Set property AutoFlush.

Declaration
Code: Copy
Sub SetAutoFlush(prmValue As Boolean)
Example
Code: Copy
Ini.SetAutoFlush(True)

ReadString
Read a string value based on key inside a section.

Declaration
Code: Copy
Sub ReadString(prmSectionName As String, prmKeyName As String, prmDefault As String) As String
Example
Code: Copy
Dim emailAddr As String = Ini.ReadString("Config", "email", "")

ReadInteger
Read an integer value based on key inside a section.

Declaration
Code: Copy
Sub ReadInteger(prmSectionName As String, prmKeyName As String, prmDefault As Int) As Int
Example
Code: Copy
Dim userAge As Int = Ini.ReadInteger("Config", "age", 18)

ReadBool
Read a boolean value based on key inside a section.

Declaration
Code: Copy
Sub ReadBool(prmSectionName As String, prmKeyName As String, prmDefault As Boolean) As Boolean
Example
Code: Copy
Dim isMarried As Boolean = Ini.ReadBool("Config", "married", False)

WriteString
Write a string value on key inside a section. Returns False when parameters invalid.

Declaration
Code: Copy
Sub WriteString(prmSectionName As String, prmKeyName As String, prmValue As String) As Boolean
Example
Code: Copy
Ini.WriteString("Config", "email", "[email protected]")

WriteInteger
Write an integer value on key inside a section. Returns False when parameters invalid.

Declaration
Code: Copy
Sub WriteInteger(prmSectionName As String, prmKeyName As String, prmValue As Int) As Boolean
Example
Code: Copy
Ini.WriteInteger("Config", "age", 23)

WriteBool
Write a boolean value on key inside a section. Returns False when parameters invalid.

Declaration
Code: Copy
Sub WriteBool(prmSectionName As String, prmKeyName As String, prmValue As Boolean) As Boolean
Example
Code: Copy
Ini.WriteInteger("Config", "married", True)

Flush
Perform writing to file. It might be automated by setting AutoFlush to True.

Declaration
Code: Copy
Sub Flush
Example
Code: Copy
Ini.Flush
 
Last edited:
Thank you for sharing,
Just one thing, you should mention that all Section and KeyName SHOULD be upper case
 
Back
Top