issue with class interface method not getting called

I have a window that has the class interface ssWired.Observers.GotConnectionClosedInterface


ssWired.Observers.GotConnectionClosedRegisterObserver self

ConnectionClassThread.Close (this is a method I added to the sub-class)

ssWired.Observers.GotConnectionClosedNotify NEW ssWired.GotConnectionClosedClass(me)  // broadcast the closure


[code] // GotConnectionClosed

if (pData <> Nil) then
for each o as ssWired.Observers.GotConnectionClosedInterface in GotConnectionClosedObservers
o.GotConnectionClosed pData
end if[/code]

ssWired.Observers.GotConnectionClosedObservers (property)

Private GotConnectionClosedObservers() As GotConnectionClosedInterface

Now the fun starts :slight_smile:

Everything works fine, and all the other objects and windows that have that class interface get notified as they should, but I have one particular window sub-class that does not get called… In the for each o loop, the loop skips over the window… I modified the loop to the following:

[code] // GotConnectionClosed

if (pData <> Nil) then
for each o as Variant in GotConnectionClosedObservers
DIM tIsA As Boolean = (o IsA ssWired.Observers.GotConnectionClosedInterface)
end if[/code]

In the modified code the loop runs for the window and the variable tIsA returns TRUE… I even tried to type cast the variant, but it still does not fire off… All the other class interfaces on that window work, just not this one…

Does that window subclass actually implement the method? Is there a subclass of that class? Some method is being called, but since methods are virtual, it may not be the one you expect.

The window has the method
As far as I can tell, in the unmodified script it doesn’t run the inner code (I put a break point in there)…

When you say “The window has the method” are you sure the method’s parameter is of the correct type (as I understand it from your code there is one parameter “pData”)?

Yes, when the class interface is added to the window the IDE automatically adds the methods from the interface…

Yes, that’s correct, but if a method in the interface is created later, it is not automatically added to classes implementing the interface.

yup, the class interface was created with the one method and then added to the window and the method was automatically populated… I even removed the method and the interface, restarted Xojo and re-did it, but still nothing…

You can see the last two lines in the picture, that the method does get called for the other windows/objects…

Can’t see the picture. Make a simple example for us to check and verify that your observer really get’s added.

Can’t edit my post, hopefully you can see this picture

The three objects (two windows and one container control) are in the property array… The UserInfoWin instance is the one that is failing…

You could filter out the problematic window in the loop and the cast it to its window type:

if (pData <> Nil) then for each o as Variant in GotConnectionClosedObservers If o IsA TheProblematicWindowClass Then Dim win As TheProblematicWindowClass = TheProblematicWindowClass(o) break End next end if

(sorry, pressed the button by accident)
… and then further investigate the win variable with introspection to see if it implements the requested method.

Type casting to the window class didn’t work either… Will try the introspection idea… Off to the docs!

What’s the error text of the failing type casting?

No error, the inner code of the if statement does not run, same as the original unmodified code… I’m exploring the introspection idea, just taking a few minutes for me to figure out the sample code from the docs to what I need… Thanks for your help and ideas where to look :slight_smile:

The method shows up in the introspection list of methods…

Calling the method directly does work, so not an issue with the method…

Good. But still, in your loop you must be able to cast the o variable to the variable of type “ProblematicWindow”
So in two steps:

  1. can you filter out the window in the loop?

if (pData <> Nil) then for each o as Variant in GotConnectionClosedObservers If o IsA TheProblematicWindowClass Then Break// Do you get here? ... End
2. then try to cast

Dim win As TheProblematicWindowClass = TheProblematicWindowClass(o)

Where does it fail?

This time around it did the break and the cast… woot :slight_smile:
Will see about calling the method now from the loop…