I have the following code, which appears to be working. However it doesn't
look right. The part I am wondering about is the logic in
DisconnectEvent s(). This logic creates a new delegate and then expects to
find that delegate in the list of event handlers.
What is the proper way of writing this?
Regards,
Bob Rundle
public void ConnectEvents(j oaCollectionEve nts events)
{
OnChanged += new OnChangedDelega te(events.OnCha nged);
OnAdded += new OnAddedDelegate (events.OnAdded );
OnRenamed += new OnRenamedDelega te(events.OnRen amed);
OnRemoved += new OnRemovedDelega te(events.OnRem oved);
}
public void DisconnectEvent s(joaCollection Events events)
{
OnChanged -= new OnChangedDelega te(events.OnCha nged);
OnAdded -= new OnAddedDelegate (events.OnAdded );
OnRenamed -= new OnRenamedDelega te(events.OnRen amed);
OnRemoved -= new OnRemovedDelega te(events.OnRem oved);
} 2 1852
Bob Rundle <ru****@rundle. com> wrote: I have the following code, which appears to be working. However it doesn't look right. The part I am wondering about is the logic in DisconnectEvent s(). This logic creates a new delegate and then expects to find that delegate in the list of event handlers.
What is the proper way of writing this?
That's fine. So long as it's got the same target as the original
delegate, and the same method, it'll match.
(If you'd changed the value of "events", for example, nothing would
have been removed.)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Bob,
You could also keep a reference to the added delegates:
OnChangedDelega te ocHandler = null;
public void ConnectEvents(j oaCollectionEve nts events)
{
ocHandler = new OnChangedDelega te(events.OnCha nged);
OnChanged += ocHandler;
}
public void DisconnectEvent s(joaCollection Events events)
{
if ( ocHandler!= null )
OnChanged -= ocHandler;
}
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Bob Rundle" <ru****@rundle. com> wrote in message
news:u%******** *******@TK2MSFT NGP12.phx.gbl.. . I have the following code, which appears to be working. However it
doesn't look right. The part I am wondering about is the logic in DisconnectEvent s(). This logic creates a new delegate and then expects to find that delegate in the list of event handlers.
What is the proper way of writing this?
Regards, Bob Rundle
public void ConnectEvents(j oaCollectionEve nts events) { OnChanged += new OnChangedDelega te(events.OnCha nged); OnAdded += new OnAddedDelegate (events.OnAdded ); OnRenamed += new OnRenamedDelega te(events.OnRen amed); OnRemoved += new OnRemovedDelega te(events.OnRem oved); }
public void DisconnectEvent s(joaCollection Events events) { OnChanged -= new OnChangedDelega te(events.OnCha nged); OnAdded -= new OnAddedDelegate (events.OnAdded ); OnRenamed -= new OnRenamedDelega te(events.OnRen amed); OnRemoved -= new OnRemovedDelega te(events.OnRem oved); }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: TP-Software |
last post by:
Hi,
I have a ChatFormCollection class which holds a collection of the class
ChatForm which inherits from Form.
MainForm has an instance of ChatFormCollection.
When a ChatForm instance is created it is added to the ChatFormCollection of
MainForm.
this.parent.ChatForms.Add(this);
|
by: Martin Lapierre |
last post by:
How can I remove the default exception handler handler?
When adding a custom handler, I can't get rid of the VS.NET unhandled
exception dialog.
Ex:
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new
UnhandledExceptionEventHandler(MyHandler);
MyHandler gets called AFTER the default VS.NET unhandled exception handler
|
by: Patrick |
last post by:
Hello
I have the following problem. I have an aspx Page. This page contains an
ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit
the event of that button trough the WYSIWYG editor, so I co to the
CodeBehind and add the Event in the InitializeComponent() Method like this
this.lbTest.Click += new System.EventHandler(this.lbTest_Click);
so far, all works fine. now if i go to the WYSIWYG editor, add another...
|
by: Charles Law |
last post by:
I think I asked the wrong question last time, so I am starting a separate
post to distinguish them.
Take five classes: ClassA and ClassW...Z
ClassA raises five events: Event1...5
ClassW...Z handle some combination of these events. For example
ClassW handles Event1, 2 and 5
|
by: MikeT |
last post by:
This may sound very elementary, but can you trap when your object is
set to null within the object?
I have created a class that registers an event from an object passed
in the constructor. When my object is destroyed, I want my object to
un-register this event. If I don't then the object would never be
destroyed until the object I passed in the constructor is destroyed.
I have implemented a Dispose(), Dispose(bool), and ~Finalize...
| |
by: gnassar |
last post by:
Essentially my problem is that .NET 2005 is removing my event
handlers. There's no real special things about my project, it just
continually removes them all.
It starts on the open of a solution. The screen flashes and
immediately I can undo something. I look at the undo list and it says
designer generated code. When I undo it, all of my event handlers come
back. This is a very annoying issue has anyone solved this problem?
-G
|
by: m0nkeymafia |
last post by:
I read about this technique to basically allow you to have a file with
behaviours and javascript events that attach to various dom objects
and events but are not done inline.
so its basically a css file but for javascript.
anyone know what it is called or where i can get more information
about it??
thanks
|
by: MikeP |
last post by:
Hi there,
I've tried hunting for this in the C# specs but can't find the relevant
info. Does anyone know what the official rule says (or doesn't say) about
removing an event more than once. If you apply "+=" to assign an event for
instance, can you safely apply "-=" more than once or is this implementation
dependent (and possibly dangerous). Thanks very much
|
by: bgold12 |
last post by:
Hey, I just want to make sure that when I remove an element I don't
have to worry about the events listeners I added previously to the
element. For example:
// get the element by its id
elem = document.getElementById('elemId');
// attach the event listener
if (elem.addEventListener) { // std
elem.addEventListener(eventName, functionRef, false );
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |