One thing I want to achieve is to gather a lot of different variables (in my case also known as "settings" or "options") in to a central place, e.g. a structured array. It will include information such as the type (#PB_Byte, #PB_String etc.) and of course the value itself.
The problem is how to properly deal with the set/get procedures? If I would only allow integer, byte etc. this wouldn't be an issue. However I also want to support float and even string "values".
Long story short, I'm thinking of something like this:
Code: Select all
Procedure SettingsInit()
Settings(#Option1Byte)\Type = #PB_Byte
Settings(#Option4String)\Type = #PB_String
; ...
EndProcedure
Macro SettingsSet(ID, Value) ; Macro, otherwise 'Value' couldn't have any type
Select Settings(ID)\Type
Case #PB_Byte : Settings(ID)\ValueB = Value
Case #PB_String : Settings(ID)\ValueS = Value
EndSelect
EndMacro
Procedure SettingsGet(ID)
Select Settings(ID)\Type
Case #PB_Byte : Value = Settings(ID)\ValueB
Case #PB_String : Value = Settings(ID)\ValueS
EndSelect
ProcedureReturn Value
EndProcedure
SettingsInit() ; Setup of the internals
SettingsSet(#Option1Byte, 123)
SettingsSet(#Option4String, "test")
Byte = SettingsGet(#Option1Byte) ; Should put 123 in 'Byte'
String$ = SettingsGet(#Option4String) ; Should put "test" in 'String$'