EmitEventHook Bug

BlitzMax Forums/MaxGUI Module/EmitEventHook Bug

Scienthsine(Posted 2011) [#1]
It seems that only the first event hook that is called for the EmitEventHook id contains a valid event.

I was planning on switching to eventhooks so I could have multiple instances of self contained GUI windows, each handling their own events automatically.

I took the example from the docs and added another 'Applet', but although it gets it's event handler called, the event passed to it is null.

Am I missing something?


EDIT
Nevermind, found this in the docs under 'RunHooks' shortly after:
The first hook function is called with the provided data object. The object returned by this function is then passed as the data parameter to the next hook function and so on. Therefore, hook functions should generally return the data parameter when finished.



So, I advise the sample code have 'Return data' added as the last line of 'eventhook()'. This causes it to run properly.

Last edited 2011


AdamRedwoods(Posted 2011) [#2]
Right, I think that got me once, too.

My understanding is that it enables an event to broadcast to a lot of routines, OR if an event is specific to one routine, then it can pull it off the stack for no one else to deal with.

I may be mistaken, but do you want to switch the eventhook to a method, so then you can check ( if TApplet(data) = self ) to see if the two match, if so, then pull the event data off, otherwise return the event data. But I forget if methods can be put into hooks.


(and a minor note, I think convention is that Create is a function since you usually call it only once with the type. So you'd put your NEW in the function as "local temp:TApplet = New TApplet" then just "temp.window = creatwindow()...etc..." and finally "return temp"..... but this is up to you.)


jsp(Posted 2011) [#3]
I think convention is that Create is a function...

A function is often used, but a method is more flexible.