Page 1 of 1
Bind...Event() with additional paramter
Posted: Fri Oct 06, 2017 7:22 am
by Josh
An additional parameter in the Bind... Event () commands would be very useful, e. g. for a this-pointer. Ok, I can store this as Data in the Window/Gadget, but that's not very elegant.
In the forum I found several posts about this, but obviously nobody thought about posting this also in the Wishlists.
Re: Bind...Event() with additional paramter
Posted: Fri Oct 06, 2017 10:59 am
by Bisonte
Is EventData() an option ?
Re: Bind...Event() with additional paramter
Posted: Fri Oct 06, 2017 1:52 pm
by Justin
+1 It is a very common practice for a callback to supply a value that gets passed to the callback.
Eventdata is just for customs events no? And may be in use for other things.
I have been missing this since events were introduced but i did not bother to ask because i have very few hopes it gets included.
Re: Bind...Event() with additional paramter
Posted: Sat Oct 07, 2017 12:09 am
by Demivec
Do you have example code that demonstrates the way the proposed change would be used?
Re: Bind...Event() with additional paramter
Posted: Sat Oct 07, 2017 9:25 am
by Mijikai
Demivec wrote:Do you have example code that demonstrates the way the proposed change would be used?
It would be very helpful for custom/complex GUIs or games.
Im not sure why anyone would prefer this or EventData() over a additional parameter.
Code: Select all
*Chess.CHESS_STRUCT = GetGadgetData(EventGadget())
+1
Re: Bind...Event() with additional paramter
Posted: Sat Oct 07, 2017 12:39 pm
by mk-soft
I think is a god idea
This work
Code: Select all
;-TOP
; Comment : Module MyBindEvent with EventData
; Author : mk-soft
; Version : v1.0x
; Created : 07.10.2017
; Updated :
; Callback syntax : BindGadgetCB(EventData)
DeclareModule MyBindEvent
Declare MyBindGadgetEvent(Gadget, *Callback, EventType = #PB_All, EventData = 0)
Declare MyUnbindGadgetEvent(Gadget, *Callback, EventType = #PB_All)
EndDeclareModule
...
Link:
http://www.purebasic.fr/english/viewtop ... 12&t=69352
Re: Bind...Event() with additional paramter
Posted: Sat Oct 07, 2017 4:30 pm
by Mijikai
mk-soft wrote:I think is a god idea
This work
...
...now imagine we would not need to do workarounds