Determinig if a handler exists from code

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

Hi all,

Does anyone a way to determine if a handler has been assigned to a delegate,
at runtime? I'm converting some C# code and it tests whether or not the
handler has been assigned. Unfortuntely, VB doesn't support the technique.

Thanks,

Doug
 
* "Doug said:
Does anyone a way to determine if a handler has been assigned to a delegate,
at runtime? I'm converting some C# code and it tests whether or not the
handler has been assigned. Unfortuntely, VB doesn't support the technique.

You don't need to test that in VB. Simply use 'RaiseEvent'.
 
Thanks for the quick response Herfried,

What I was looking for was a VB equivalent of this C# snippet. VB does
not allow testing the delegate for a handler. It assumes you want to
raise the event.

In hindsight, all it seems to do is not raise the event if no handler is
present. May not be worth the effort...

C#-------
public event QueryShowTheDragCursorEventHandler
QueryShowTheDragCursor;

protected virtual void
OnQueryShowTheDragCursor(QueryShowTheDragCursorEventArgs e)
{
//If handler present then raise the event
if(QueryShowTheDragCursor != null)
QueryShowTheDragCursor(this, e);

}



VB-----
Protected Overridable Sub OnQueryShowTheDragCursor(ByVal e As
QueryShowTheDragCursorEventArgs)
If (Not QueryShowTheDragCursor Is Nothing) Then
RaiseEvent QueryShowTheDragCursor(Me, e)
End If
End Sub


Thanks for your time,

Doug
 
* Doug said:
What I was looking for was a VB equivalent of this C# snippet. VB does
not allow testing the delegate for a handler. It assumes you want to
raise the event.

In hindsight, all it seems to do is not raise the event if no handler is
present. May not be worth the effort...
If (Not QueryShowTheDragCursor Is Nothing) Then
RaiseEvent QueryShowTheDragCursor(Me, e)

The 'If...Then...' is not required.
 
Back
Top