Code: Alles auswählen
; based on code by fred: http://www.purebasic.fr/english/viewtopic.php?p=323668#p323668
DeclareModule Props
Declare.i GetProp(Gadget, Name.s) ; Get a property from the given #Gadget. Returns 0 if the property does not exist
Declare.s GetPropStr(Gadget, Name.s) ; Get a propertystring from the given #Gadget. Returns "" if the property does not exist
Declare SetProp(Gadget, Name.s, Value) ; Set a property on the given #Gadget
Declare SetPropStr(Gadget, Name.s, Value.s) ; Set a propertystring on the given #Gadget
Declare RemoveProp(Gadget, Name.s) ; Remove a property from the given #Gadget (if it exists)
Declare RemoveAllProps(Gadget) ; Remove all properties (and the map) from a given #Gadget.
EndDeclareModule
Module Props
EnableExplicit
Structure PropType
val.i
text.s
EndStructure
Structure PropMap
Map PropName.PropType()
EndStructure
Global NewMap Props.PropMap()
Procedure GetProp(Gadget, Name.s)
Name = UCase(Name)
If Props(Str(Gadget))
ProcedureReturn Props()\PropName(Name)\val
EndIf
EndProcedure
Procedure.s GetPropStr(Gadget, Name.s)
Name = UCase(Name)
If Props(Str(Gadget))
ProcedureReturn Props()\PropName(Name)\text
EndIf
EndProcedure
Procedure SetProp(Gadget, Name.s, Value)
Name = UCase(Name)
Props(Str(Gadget))\PropName(Name)\val = Value
EndProcedure
Procedure SetPropStr(Gadget, Name.s, Value.s)
Name = UCase(Name)
Props(Str(Gadget))\PropName(Name)\text = Value
EndProcedure
Procedure RemoveProp(Gadget, Name.s)
Name = UCase(Name)
If Props(Str(Gadget))
DeleteMapElement(Props()\PropName(), Name)
EndIf
EndProcedure
Procedure RemoveAllProps(Gadget)
DeleteMapElement(Props(), Str(Gadget))
EndProcedure
EndModule
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
CompilerIf Not #PB_Compiler_OS = #PB_OS_Windows
#BS_MULTILINE = 0
CompilerEndIf
UseModule Props
Procedure ButtonHandler()
Protected gadget
gadget = EventGadget()
Debug GetPropStr(gadget, "value1")
Debug GetPropStr(gadget, "value2")
EndProcedure
Procedure mywindow()
If IsWindow(1)
UnbindGadgetEvent(0, @ButtonHandler())
RemoveAllProps(0)
UnbindGadgetEvent(1, @ButtonHandler())
RemoveAllProps(1)
EndIf
OpenWindow(1, 0, 0, 400, 300, "my window", #PB_Window_WindowCentered, WindowID(0))
ButtonGadget(0, 10, 10, 180, 50, "Click me" + Chr(13) + "hier hat er probleme beim auslesen", #BS_MULTILINE)
ButtonGadget(1, 100, 100, 180, 30, "Click me")
ButtonGadget(2, 100, 200, 180, 30, "end")
SetPropStr(0, "value1", "my first item")
SetPropStr(0, "value2", "my first item value")
BindGadgetEvent(0, @ButtonHandler())
SetPropStr(1, "value1", "my seccond item")
SetPropStr(1, "value2", "my seccond item value")
BindGadgetEvent(1, @ButtonHandler())
EndProcedure
Procedure Main()
Protected Event
OpenWindow(0, 100, 100, 500, 400, "Click test", #PB_Window_SystemMenu)
ButtonGadget(3, 10, 10, 180, 30, "open my window", 0)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 2
CloseWindow(1)
Case 3
mywindow()
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndProcedure
Main()
CompilerEndIf