Is it possible to tell whether an Event has been implemented?

If a class defines an Event Definition, is it possible at runtime to determine whether the Event has been implemented?

What I’m trying to do is raise an event that should return something if implemented, otherwise I’ll just use the input arg to the event as is.

Because the result of the event should be a String, I’m struggling to find a way of checking whether the result of the Raise Event is empty because the event wasn’t implemented or because it was implemented but was actually meant to be empty (it’s legitimate that an empty string be returned).

Put the return value in a ByRef parameter instead and have the event return a Boolean. If it’s handled, it will return True and your super will know to use the value in the parameter.

Event MyEvent (ByRef returnParam As String) As Boolean

Doh! That’s used all over the Xojo framework, I should have thought of that!

Thanks Kem.

sometimes I also return the parameter from the event
if the returned parameter is nil, most of the time it tells you that the event is not implemented.
this works if the returned parameter can be niled, and only by the event.

You can also use introspection to look for event_nameOfTheEvent

This is an implementation detail for controls on a layout and not something to rely on. It won’t work with AddHandler or events not implemented on a layout, for example.

Ah yes, I had forgotten about that. For controls, I usually do like Kem said.

So that means the framework could change how this is implemented at any time? If so, I’ll avoid that.

Yeah, don’t rely on the Event_ prefix.

[quote=317245:@Jean-Yves Pochez]sometimes I also return the parameter from the event
if the returned parameter is nil, most of the time it tells you that the event is not implemented.
this works if the returned parameter can be niled, and only by the event.[/quote]
Yeah, would have preferred this simpler route. Unfortunately I’m only handling a primitive type (String), so there’s no scope for checking for Nil.

if the string is supposed to be non-empty, then an empty string can be considered as nil ?
I already used that method with a string returned this way.

you can also return a variant for the parameter, and the variant can be niled, or have a string value.

Unfortunately no, as mentioned in my original post, “it’s legitimate that an empty string be returned”.

then use a variant, or a byref and a boolean.

Another option is to create classes that stand in for the primitive types and will auto-convert to them. For example, a ParamString class that will act like a string but can be nil.

Event MyEvent () As ParamString
  return "something" // Will auto-convert to a ParamString
End

Addhandler will generate an error when a handler is already present. That can be used to detect if a handler is already present.