[Gambas-user] Settings: how to get (unknown) Keys?
Benoît Minisini
gambas at ...1...
Sat Jul 5 14:47:51 CEST 2014
Le 18/06/2014 15:08, wig a écrit :
>
> How the get the (unknown keys) from a Settings file?
>
>
> Terminology of Keys and "Slot" for the group of keys in a settings file
> taken from documentation;
>
> This gives the names of the slots:
>
>
> Dim SettingsToImport As New Settings(User.Home &/
> ".config/gambas3/gambas3.conf")
>
> Dim sKeySlot As String
> Dim iSlotCounter As Integer
>
> For Each sKeySlot In SettingsToImport.Keys
> Debug sKeySlot
> Inc iSlotCounter
> Next
> Debug " - - - - " & iSlotCounter
>
>
> Works fine, gives me all the slotnames, and the count of e.g.23:
>
>> Editor
>> FColorChooser
>> FConnectionEditor
> ...
>> gb.form.mdi/FShortcut
>> gb.form.mdi/FToolbarConfig
>> gb.form.mdi/Toolbars/main
>> - - - - 23
>
> Next step; I want to have the keys themselves. But how? (assuming I do
> not know the keynames)
>
>
> Dim SettingsToImport As New Settings(User.Home &/
> ".config/gambas3/gambas3.conf")
>
> Dim sKey As String
> Dim iKeyCounter As Integer
>
> Dim hSettingsKeys As _Settings_Keys ' what I found in gb.settings docum.
>
> For Each sKeySlot In SettingsToImport.Keys
> Debug sKeySlot
> Inc iSlotCounter
>
> hSettingsKeys = SettingsToImport.Keys[sKeySlot] ' docum says
> hSettings.Keys [ Parent As String ]
>
> For Each sKeySlot In hSettingsKeys
> Inc iKeyCounter
> Debug iKeyCounter & ": " & sKey
> Next
>
> Next
>
>
>
> Doesn't crash, doesn't freeze, but gives the output:
>
>> Editor
>> 1: Font
>> 2: KeywordsUseUpperCase
>> KeywordsUseUpperCase
>
>
> That's all, it stops.
>
> (I want to import a Settings file, not use it for my app itself; I know
> how to save and use settings for my app).
>
> This in Gambas 3.4.1 on OpenSuse 13.1/KDE
>
>
> WiG.
>
Well, I admit that the Settings interface is weird for that. :-/
For the moment, you can't imbricate enumerations of the Keys property,
unless you first put all keys in an intermediate string array.
Something like that:
Public Sub GetAllKeys(hSettings As Settings, Optional sParent As String,
Optional aResult As String[]) As String[]
Dim aKeys As New String[]
Dim sKey As String
For Each sKey In hSettings[sParent].Keys
aKeys.Add(sKey)
Next
If Not aResult Then aResult = New String[]
For Each sKey In aKeys
aResult.Add(sKey)
aResult.Insert(GetAllKeys(hSettings, sKey, aResult))
Next
Return aResult
End
Beware, I wrote that code without testing it!
--
Benoît Minisini
More information about the User
mailing list