So in the interest of full disclosure, what I am about to post does compile, but it doesn’t work the way I wanted it to. We’ll see if the astute reader can see my mistake…
So in the handling method for my delegate, I have the following:
ConnectedCallback is the instance of the delegate in my object, MyDevice. This delegate handler is to handle a TCPSocket connected event.
Private Sub HandleConnected(sender as MyDevice)
If ConnectedCallback <> nil Then
If ConnectedCallback <> Nil Then
Now the signature for the SetHanlders event was:
Event SetHandlers(del as Object)
Now, the method in my control that has this object as a property looks like:
Private Sub Device_SetHandlers(m as MyDevice, del as object)
If del IsA MyDevice.ConnectedCallback Then
ElseIf del IsA MyDevice.ParametersLoadedCallback Then
So did you see the problem?
Well, the problem is my callback is NIL when I raise the event. So the object is NIL! DOH! It never ends up returning what I want.
So I am sure that if the delegate object was not Nil, you could easily do this. For me, I changed to using an enum and set different enum values to check for and changed the Device_SetHandlers subroutine to set the proper delegates based on the enum value.
I’m doing this because I want to change where handlers for an object occurs when a specific window is open. Later after that window is closed, the handlers are all set to Nil and so the first window isn’t handling any of these events. So then when an event comes in I want to give myself the option of handling it and assigning a new handler. It works quite well…