PDA

View Full Version : IniFile - module for INI file handling



Petr Schreiber
29-04-2015, 19:39
The INIFile module is easy to use implementation of INI file handling for thinBasic.

It is provided with full source code, unit tests and binaries here:
https://github.com/petrSchreiber/thinBasic_iniFile

How to use:
Get the DLL from https://github.com/petrSchreiber/thinBasic_iniFile/releases/latest

Place the thinBasic_iniFile.dll to Mod directory inside your thinBasic installation. Since then, you should be able to reference the module easily as:



uses "iniFile"


Examples of usage

To make work with multiple files easier, and to avoid specifying the file name over and over again, module provides simple object:



Uses "IniFile", "Console"

' -- Hook it to any file you need
Dim config As IniFile
config = New IniFile(APP_SourcePath + "settings.ini")

' -- Write data this way - first is section, then key
config.SetKey("Screen", "Width", "1920")
config.SetKey("Screen", "Height", "1080")

config.SetKey("User", "Name", "DarthVader")
config.SetKey("User", "Password", "Force")


' -- Read the data back, even with default values
PrintL config.GetKey("Screen", "Width") + "x" + config.GetKey("Screen", "Height") + "@" + config.GetKey("Screen", "BitDepth", "32")
PrintL

' -- List sections
PrintL "Sections:", config.GetSections(",")
PrintL

' -- List keys
PrintL "Keys for Screen:", config.GetKeys("Screen", ",")
PrintL

PrintL "Keys for User:", config.GetKeys("User", ",")
PrintL

WaitKey

Let me know if you need anything to be added.

Petr

Petr Schreiber
12-03-2016, 21:10
Cleaned up the code and shared at GitHub, please see the first post for links and info.


Petr

Billbo
13-03-2016, 14:18
Petr,

The wiki link in your "How to use" link is on thinBasic_enVar.dll, not thinBasic_iniFile.dll.

Bill

Petr Schreiber
13-03-2016, 21:13
Fixed, thank you very much!


Petr

Billbo
13-03-2016, 22:55
Petr,

Thanks, as always. It is okay, now.

Bill

ErosOlmi
18-03-2016, 08:26
Petr,

I'm fascinated by your implementation of the INI class: it is so elegant.

Do you mind if I get it and add into official INI module?
I think I will release INI module in GitHub

Thanks a lot
Eros

PS: next thinBasic version will have something like DIM ... AS ... NEW ... I'm finishing to test it:


Dim config As New IniFile(APP_SourcePath + "settings.ini")


Current syntax will continue to be valid to be used when it is not possible to start constructor during variable declaration, that is:

Dim config As IniFile
'...
config = New IniFile(APP_SourcePath + "settings.ini")

Petr Schreiber
18-03-2016, 21:21
Hi Eros,

please do merge as you wish :)

That new syntax looks tasty and saves some typing, yummy!


Petr