Here it is - a little gift from me (as you will see there is not much to it - really...).
This code shows how to do it with pb.
I'm sure some users out there will make several variants out of it... even with Linked Lists.
Code: Select all
; Event Driven Coding can be so easy.
; PureBasic only code... no external lib necessary.
; (c) 2005 - by Franco (aka fsw)
; done from scratch in a few minutes
;- Start Main
Declare Button_1_Function()
;MaxObjects(0) is used to store the actual used number
;you could do it with linked lists too...
MaxObjects = 10 ; because there is no 'redim preserve' in pb - bummer...
Global Dim ObjectID(MaxObjects)
Procedure GetNewObjectID()
ObjectID(0) = ObjectID(0) + 1
ProcedureReturn ObjectID(0)
EndProcedure
Procedure ConnectTheGadgetToFunction(EventID, Function)
ObjectID(EventID) = Function
EndProcedure
Procedure CallStoredEventFunction(EventID)
CallFunctionFast(ObjectID(EventID))
EndProcedure
If OpenWindow(1,100,200,320,240,"Test",#PB_Window_SystemMenu) = 0 : End : EndIf
PB_Button_0 = GetNewObjectID()
ButtonGadget(PB_Button_0,100,50,100,50,"Button ")
ConnectTheGadgetToFunction(PB_Button_0, ?Button_0_Function) ; it works with labels
PB_Button_1 = GetNewObjectID()
ButtonGadget(PB_Button_1,100,150,100,50,"Button ")
ConnectTheGadgetToFunction(PB_Button_1, @Button_1_Function()) ; it works with procedures
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
CallStoredEventFunction(EventGadget())
EndSelect
Until Event = #PB_Event_CloseWindow
End
;- User Functions
Button_0_Function:
MessageRequester("Test Button_0", "It works...",0)
Return
Procedure Button_1_Function()
MessageRequester("Test Button_1", "It works too...",0)
EndProcedure

ps: my first pb code after a few month and it works
