Properties module - useful module for working with properties / ini files

Erel

B4X founder
Staff member
Licensed User
Longtime User
Almost every application needs to use some sort of configuration file to store configurable values.
The attached Properties module, can load and save keys and values in a simple syntax.
This library uses hashtables from agraham's collections library to store the pairs of keys and values in an efficient data structure.
You can use this module to work with any number of properties files.
A (very) small example is also included in the zip file.
B4X:
Sub App_Start
    'Load an existing properties file:
    [B]p = Properties.Load("test.ini")[/B] 'Returns the handle to the properties table.
    ListBox1.Add("Width: " & [B]Properties.GetProperty(p,"Width")[/B])
    ListBox1.Add("Height: " & [B]Properties.GetProperty(p,"Height")[/B])
    ListBox1.Add("Name: " & [B]Properties.GetProperty(p,"Name")[/B])
    Form1.Show
    
    'Change some properties and save the file:
    [B]Properties.AddProp(p,"Width",333)
    Properties.AddProp(p,"Height",111)
    Properties.AddProp(p,"Name","New Name")
    Properties.Save(p,"test.ini")[/B]
End Sub

The file syntax is:
B4X:
'This is a comment
'Key=Value

Width=200
Name=Some Name
Height=300
 

Attachments

  • Properties.zip
    6.8 KB · Views: 571

hzimmer3

Member
Licensed User
Longtime User
Properties

I find this very interesting for handling property files,
but I wonder how I can use this in Basic4Android.
Do I need to include the library collection, how?

Thanks,

Helmut
Cologne/Germany
 
Top