Named Properties for Gadgets like SetProp/GetProp (All OS)
Posted: Sat Jul 04, 2020 4:58 pm
Hello, had too much time.
With windows there is the API SetProg and GetProp.
But this works better for all OS also with maps very well and need only some macros.
Update v1.03
- Change FreeProperties(...) - #PB_All deleted all properties of not exists gadgets
- Added ClearProperties() - Clear all properties
With windows there is the API SetProg and GetProp.
But this works better for all OS also with maps very well and need only some macros.
Update v1.03
- Change FreeProperties(...) - #PB_All deleted all properties of not exists gadgets
- Added ClearProperties() - Clear all properties
Code: Select all
;-TOP
; Named Properties for Gadgets by mk-soft, v1.03, 04.07.2020
Structure udtPropertyValue
VarType.i
StructureUnion
iVal.i
fltVal.f
dblVal.d
EndStructureUnion
sVal.s
EndStructure
Structure udtProperty
Map Value.udtPropertyValue()
EndStructure
Global NewMap MapProperty.udtProperty()
Macro SetPropertyInteger(_Gadget_, _Name_, _Value_)
MapProperty(Str(_Gadget_))\Value(_Name_)\VarType = #PB_Integer
MapProperty()\Value()\iVal = _Value_
EndMacro
Macro SetPropertyFloat(_Gadget_, _Name_, _Value_)
MapProperty(Str(_Gadget_))\Value(_Name_)\VarType = #PB_Float
MapProperty()\Value()\fltVal = _Value_
EndMacro
Macro SetPropertyDouble(_Gadget_, _Name_, _Value_)
MapProperty(Str(_Gadget_))\Value(_Name_)\VarType = #PB_Double
MapProperty()\Value()\dblVal = _Value_
EndMacro
Macro SetPropertyString(_Gadget_, _Name_, _Value_)
MapProperty(Str(_Gadget_))\Value(_Name_)\VarType = #PB_String
MapProperty()\Value()\sVal = _Value_
EndMacro
; ----
Macro GetPropertyInteger(_Gadget_, _Name_)
MapProperty(Str(_Gadget_))\Value(_Name_)\iVal
EndMacro
Macro GetPropertyFloat(_Gadget_, _Name_)
MapProperty(Str(_Gadget_))\Value(_Name_)\fltVal
EndMacro
Macro GetPropertyDouble(_Gadget_, _Name_)
MapProperty(Str(_Gadget_))\Value(_Name_)\dblVal
EndMacro
Macro GetPropertyString(_Gadget_, _Name_)
MapProperty(Str(_Gadget_))\Value(_Name_)\sVal
EndMacro
; ----
Macro GetPropertyVarType(_Gadget_, _Name_)
MapProperty(Str(_Gadget_))\Value(_Name_)\VarType
EndMacro
Macro Properties(_Gadget_)
MapProperty(Str(_Gadget_))
EndMacro
Macro FreeProperties(_Gadget_) ; <- #PB_All deleted all properties of not exists gadgets
If _Gadget_ = #PB_All
ForEach MapProperty()
If Not IsGadget(Val(MapKey(MapProperty())))
DeleteMapElement(MapProperty())
EndIf
Next
Else
DeleteMapElement(MapProperty(), Str(_Gadget_))
EndIf
EndMacro
Macro ClearProperties() ; Clear all properties
ClearMap(MapProperty())
EndMacro
; ****
CompilerIf #PB_Compiler_IsMainFile
Debug "Set Properties"
SetPropertyString(1, "Text", "Hello World")
SetPropertyInteger(1, "Year", 2020)
Debug "----"
Debug "Get Properties"
Debug "Text = " + GetPropertyString(1, "Text")
Debug "Year = " + GetPropertyInteger(1, "Year")
Debug "----"
Debug "VarType of Year"
r1 = GetPropertyVarType(1, "Year")
Select r1
Case 0 : Debug "Property not exists"
Case #PB_Integer : Debug "- Integer"
Case #PB_Float : Debug "- Float"
Case #PB_Double : Debug "- Double"
Case #PB_String : Debug "- String"
EndSelect
Debug "----"
Debug "VarType of Text"
r1 = GetPropertyVarType(1, "Text")
Select r1
Case 0 : Debug "Property not exists"
Case #PB_Integer : Debug "- Integer"
Case #PB_Float : Debug "- Float"
Case #PB_Double : Debug "- Double"
Case #PB_String : Debug "- String"
EndSelect
Debug "----"
Debug "VarType of XYZ"
r1 = GetPropertyVarType(1, "XYZ")
Select r1
Case 0 : Debug "Property not exists"
Case #PB_Integer : Debug "- Integer"
Case #PB_Float : Debug "- Float"
Case #PB_Double : Debug "- Double"
Case #PB_String : Debug "- String"
EndSelect
Debug "----"
; FreeProperties(1)
Debug "List of Properties"
ForEach Properties(1)\Value()
Debug MapKey(Properties(1)\Value())
Next
Debug "---"
CompilerEndIf