Bind...Event() with additional paramter

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Bind...Event() with additional paramter

Post 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.
sorry for my bad english
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Bind...Event() with additional paramter

Post by Bisonte »

Is EventData() an option ?
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Bind...Event() with additional paramter

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Bind...Event() with additional paramter

Post by Demivec »

Do you have example code that demonstrates the way the proposed change would be used?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Bind...Event() with additional paramter

Post 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.

Image

Im not sure why anyone would prefer this or EventData() over a additional parameter.

Code: Select all

*Chess.CHESS_STRUCT = GetGadgetData(EventGadget())
+1
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Bind...Event() with additional paramter

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Bind...Event() with additional paramter

Post by Mijikai »

mk-soft wrote:I think is a god idea

This work
...
...now imagine we would not need to do workarounds :)
Post Reply