Settings (gb.settings)
Deze class beheert de algemene configuratiebestanden.
This class can be used like an object by creating a hidden instance on demand.
This class is
creatable.
This class acts like a
read /
write array.
Static properties
Static methods
FromString
|
Return a value from its settings internal string representation
|
ToString
|
Convert a value into its settings internal string representation
|
Properties
Count
|
Return the number of entries in the settings file
|
Keys
|
|
Path
|
Deze eigenschap geeft de standaard map waar configuratiebestanden worden bewaard.
|
Methods
Clear
|
Wist alle instellingen.
|
Exist
|
Return if the specified settings key has a value
|
Read
|
Initialiseert het bewuste object met waarden uit het configuratiebestand.
|
Reload
|
Verliest alle wijzigingen aan de instellingen door de bestaande instellingen terug op te halen uit het configuratiebestand.
|
Save
|
Bewaart het configuratiebestand op de harde schijf.
|
Write
|
Schrijft de instellingen van het opgegeven object in het configuratiebestand.
|
Als je deze class statisch gebruikt dan zal het standaard project-configuratiebestand gebruikt worden.
Het pad van het standaard configuratiebestand is:
User.Home &/ ".config/gambas" &/ Application.Name & ".conf"
Het configuratiebestand voor de ontwikkelomgeving is bv opgeslagen als
~/.config/gambas/gambas2.conf
Dit voorbeeld haalt de plaats van het venster op het scherm uit een bestand, op het moment dat een form geopend wordt. Als het bestand niet bestaat dan zal de standaard plaats van het venster gebruikt worden. Als de form gesloten wordt, wordt de positie bewaard in het bestand. Als bestand wordt het standaard instellingen- of configuratiebestand gebruikt.
Examples
PUBLIC SUB Form_Open()
' Update window position from settings file
' If the settings file is not found then
' use default position.
ME.Top = Settings["Window/Top", ME.Top]
ME.Left = Settings["Window/Left", ME.Left]
ME.Height = Settings["Window/Height", ME.Height]
ME.Width = Settings["Window/Width", ME.Width]
END
PUBLIC SUB Form_Close()
' Save window settings when application closes
Settings["Window/Top"] = ME.Top
Settings["Window/Left"] = ME.Left
Settings["Window/Height"] = ME.Height
Settings["Window/Width"] = ME.Width
END
Het bestand met de bewaarde instellingen, gegroepeerd onder de titel Window zou er ongeveer zo uitzien:
[Window]
Top=13
Left=18
Height=154
Width=235
Merk op dat je onmiddellijk de
Write kan gebruiken om de instellingen van een venster op te slaan, en de
Read method om ze terug op te halen.