Is there a reason that Class Interfaces don't include events?

And is there a work-around?

I would like to be able to call a range of classes via one Class Interface and set a corresponding AddHandler to to revert to the main thread once the class has finished.

Sorry, won’t work. But the interface can have a method taking delegates and do the connection for you.

You can try to cast it back then add handler using IsA.

if AClassinterfaceInstance IsA typeofclass then
 //cast to class and add handler
End if

Ah, if I understand correctly, instead of adding an AddHandler(myclass event, method), you pass a delegate for the method you want to call into the class via for example myclass.run(address of delegate). Is that correct?

Yes, but that would seem to remove the benefit of using Class Interfaces in the first place.

How so ?

A class interface method implementation is basically the “event” you can implement whatever you like. You can also use delegates as @Christian_Schmitz suggests.

A class interface is basically “a group of classes that say they at least have the same methods, but the implementation is up to the class itself to fill in”.

So you can also fill in a delegate as a parameter (or even as a return value) to one or more of those class interface methods.

In my limited understanding a Class Interface allows multiple classes to be called as if they are the same class. Therefore a loop could call a series of different classes with the same instruction (eg myInterface.run), without needing to know what the underlying class really is. So the calling method needs no other knowledge about the class that is being called and additional classes can be added that conform to the same interface without having to modify the calling method.

By introducing IsA into the calling method, now it needs knowledge of the class being called; any additional classes added would also have to be added to the calling method. Christian’s delegate method fixes that (when I can work out the mechanics :smile:)

1 Like

Whatever solution fit’s best should be used… :innocent: