PC Review


Reply
Thread Tools Rate Thread

Determinig if a handler exists from code

 
 
Doug
Guest
Posts: n/a
 
      31st Aug 2004
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


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      31st Aug 2004
* "Doug" <(E-Mail Removed)> scripsit:
> 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'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
Doug
Guest
Posts: n/a
 
      31st Aug 2004
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      31st Aug 2004
* Doug <(E-Mail Removed)> scripsit:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determinig the FQDN of a domain Timothy Jewett Microsoft VC .NET 0 7th May 2010 08:21 PM
Determinig Population membership percentages =?Utf-8?B?TWljaGVsZQ==?= Microsoft Excel Worksheet Functions 1 30th Jun 2006 05:57 PM
determinig datatype in excel =?Utf-8?B?bGF0aGE=?= Microsoft Excel Programming 1 29th Jun 2006 09:09 AM
Determinig which file is best to use lloydklein2003 Microsoft Windows 2000 File System 1 2nd Oct 2003 05:17 PM
Re: Determinig what events will be called from Page_Load ??? Teemu Keiski Microsoft ASP .NET 0 21st Aug 2003 06:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:50 AM.