I dont undestand
How can be “eventName” the same kind of “delegateMethod” ?
AddHandler eventName, delegateMethod
I dont undestand
How can be “eventName” the same kind of “delegateMethod” ?
AddHandler eventName, delegateMethod
the event method have always the object argument where you used define event.
this means if a event call a method you know where it comes from and there it is also possible to call removehandler
LOL. I was introduced to OOP with C++ and later Object Pascal (Delphi). I wish the bright young things would stop inventing new words for old concepts. The hardest part of understanding AddHandler I found was deconstructing the terminology.
An Event is a pointer to a function defined at compile time. An Event Handler is the function an Event points to. AddHandler changes the target of the pointer at runtime.
I am still not entirely sure what a Delegate is. A signature for the function a pointer to function points to??? Whatever a Delegate is I have never needed one.
In Xojo, a delegate is a method signature, so you could define a delegate like this:
Sub Callback(data as String)
And then a property like this:
Dim myMethod as Callback
MyMethod = AddressOf myCallbackMethod
The power comes from the fact that like AddHandler, you can assign them at runtime, but that you can also check them for Nil, so you can change behavior based on whether MyMethod was set at all:
If MyMethod <> Nil then
MyMethod.Invoke("hello")
End if
I’ve used this pattern for doing debug-only logging in the past, where when instantiating the class, you could say:
#If DebugBuild
MyInstance.MyMethod = AddressOf loggingCallback
#End If
it looks like
obj ← obj ← obj ← obj ← obj ← obj
if you memory the parent object and add each object an interface with method action
you could do something like this
Button Event in the last hierarchy object
Action("Hello")
method Action(msg as String)
if me.MyParent<>nil then
me.MyParent.Action(msg)
end if
and instead of string using a enumeration or something else.
Other option is using a property/flag and collect data from top to bottom triggered by a timer.