473,569 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determinig if a handler exists from code

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
Nov 21 '05 #1
3 1759
* "Doug" <dl***@panthers ys.com> 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/>
Nov 21 '05 #2
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 QueryShowTheDra gCursorEventHan dler
QueryShowTheDra gCursor;

protected virtual void
OnQueryShowTheD ragCursor(Query ShowTheDragCurs orEventArgs e)
{
//If handler present then raise the event
if(QueryShowThe DragCursor != null)
QueryShowTheDra gCursor(this, e);

}

VB-----
Protected Overridable Sub OnQueryShowTheD ragCursor(ByVal e As
QueryShowTheDra gCursorEventArg s)
If (Not QueryShowTheDra gCursor Is Nothing) Then
RaiseEvent QueryShowTheDra gCursor(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!
Nov 21 '05 #3
* Doug <an********@dev elopersdex.com> 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 QueryShowTheDra gCursor Is Nothing) Then
RaiseEvent QueryShowTheDra gCursor(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/>
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7896
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the header of the datagrid in the "ItemDataBound" method of the grid. However, once, they are added in the grid, i seem to lose the event handler for the...
4
4444
by: Mark Mikulec | last post by:
Hi there, I wonder if anyone can shed some light on a very frustrating problem. I'm running a debian linux 3.0 "woody" server, nothing special, with the latest version of postres that apt-get will allow me, which I *think* it;s 7.1 something, I don't know how to figure out the postgres version. Anywho - I'm trying to backup my databases,...
1
4999
by: malcolm | last post by:
Is there a way to test to see if an event handler hasn't already been added to an event handler listener object? This is what I am doing now as a hack: dataView.ListChanged -= new ListChangedEventHandler(dataView_ListChanged); dataView.ListChanged += new ListChangedEventHandler(dataView_ListChanged);
0
1885
by: Anonieko Ramos | last post by:
Answer. Use IHttpHandler. thanks Ro ry for coming up with this code. It processes css file to add variables. neat idea using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Caching;
10
3864
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET forums, and noone wants to touch it. I tried to attach a literal control to a placeholder: <>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>
2
1157
by: Ken Kast | last post by:
What I'm trying to do is find a way to determine at run time if a particular event handler in a UserControl has been defined. Here's a snippet of code: Public Event Button_Click As EventHandler Public WriteOnly Property ButtonClick() As System.EventHandler Set(ByVal Value As System.EventHandler) If Not Value Is Nothing Then
7
1825
by: Andrus | last post by:
I noticed that DataGridView CellValidated() and other event handler first parameter is object: Grid.CellValidated+=new DataGridViewCellEventHandler(Grid_CellValidated); .... void Grid_CellValidated(object sender, DataGridViewCellEventArgs e) { .....
11
7301
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code is run again? This is causing certain error problems. 1 Why does the code run for a print preview when the report already exists? 2 What...
7
3145
by: howardk | last post by:
I'm writing some code that loads a number of images, using the standard mechanism of assigning a src url to a newly constructed Image object, thus invoking the image-load operation. On a successful load, an image.onload handler I've previously assigned will be called. Or should be at any rate. The problem is that I need to know inside the...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.