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

  • TIniFile.bas
    5 KB · Views: 576

Xenno

Member
Licensed User
Public Methods

Initialize
It is for initializing the object.

Declaration
B4X:
Sub Initialize(prmDirName As String, prmFileName As String)

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

GetDirName
Get directory name of the INI file.

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

GetFileName
Get file name of the INI file.

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

GetAutoFlush
Get property AutoFlush.

Declaration
B4X:
Sub GetAutoFlush As Boolean

Example
B4X:
Dim IniAutoFile As Boolean = Ini.GetAutoFlush

SetAutoFlush
Set property AutoFlush.

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

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

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

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

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

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

Declaration
B4X:
Sub ReadBool(prmSectionName As String, prmKeyName As String, prmDefault As Boolean) As Boolean
Example
B4X:
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
B4X:
Sub WriteString(prmSectionName As String, prmKeyName As String, prmValue As String) As Boolean
Example
B4X:
Ini.WriteString("Config", "email", "[email protected]")

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

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

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

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

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

Declaration
B4X:
Sub Flush
Example
B4X:
Ini.Flush
 
Last edited:
Top