Okay, thanks again for the helpful replies. It seems a shame that one can't just call SetProp_() all over the place willy-nilly the same way as SetGadgetData(), without having to worry about undoing everything before closing. It's certainly much more convenient not having to call RemoveGadgetData() on hundreds of gadgets before ending an app.
In any case the only ways I've managed to handle adding unlimited properties to gadgets/controls on the fly, without having to manually remove each one individually is as follows. If someone has a better, more efficient way of easily storing/associating data/properties along with controls I'd definitely be much obliged to know about it..
1) Using a linked list along with SetProp_() to track all added properties:
Code: Select all
Structure Prop
handle.l
Property.s
Value.l
EndStructure
Global NewList Properties.Prop()
Macro SetProp(hWnd,prop,val)
SetProp_(hWnd,prop,val)
found=0
ForEach Properties()
If Properties()\handle=hWnd And Properties()\property=prop
Properties()\value=val:found=1:Break
EndIf
Next
If Not found
AddElement(Properties())
Properties()\handle=hWnd
Properties()\property=prop
Properties()\value=val
EndIf
EndMacro
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 10, 70, 250, 20, "SetProp Test", #PB_Text_Center)
SetProp(GadgetID(1),"Property1",1)
SetProp(GadgetID(1),"Property2",2)
SetProp(GadgetID(1),"Property3",3)
SetProp(GadgetID(1),"Property4",4)
SetProp(GadgetID(1),"Property5",5)
Debug GetProp_(GadgetID(1),"Property1")
Debug GetProp_(GadgetID(1),"Property2")
Debug GetProp_(GadgetID(1),"Property3")
Debug GetProp_(GadgetID(1),"Property4")
Debug GetProp_(GadgetID(1),"Property5")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
ForEach Properties()
RemoveProp_(Properties()\handle,Properties()\property)
Next
EndIf
2) Using only the linked list itself instead of API calls, for the same effect:
Code: Select all
Structure Prop
gadget.l
Property.s
Value.l
EndStructure
Global NewList Properties.Prop()
Procedure SetProp(gadgetnum,prop.s,val)
found=0
ForEach Properties()
If Properties()\gadget=gadgetnum And Properties()\property=prop
Properties()\value=val:found=1:Break
EndIf
Next
If Not found
AddElement(Properties())
Properties()\gadget=gadgetnum
Properties()\property=prop
Properties()\value=val
EndIf
EndProcedure
Procedure GetProp(gadgetnum,prop.s)
ForEach Properties()
If Properties()\gadget=gadgetnum And Properties()\property=prop
ProcedureReturn Properties()\value
EndIf
Next
ProcedureReturn 0
EndProcedure
If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(1, 10, 70, 250, 20, "SetProp Test", #PB_Text_Center)
SetProp(1,"Property1",1)
SetProp(1,"Property2",2)
SetProp(1,"Property3",3)
SetProp(1,"Property4",4)
SetProp(1,"Property5",5)
Debug GetProp(1,"Property1")
Debug GetProp(1,"Property2")
Debug GetProp(1,"Property3")
Debug GetProp(1,"Property4")
Debug GetProp(1,"Property5")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Both of these work, but are not as speed-efficient as the API SetProp_() and GetProp_() versions by themselves. I know about EnumProps_() as well, but am not sure whether it would be the ideal way of automatically removing added properties.
Any suggestions are welcome, thanks...
.