473,378 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Store added event handlers

Hi,

I add event handlers to different events of objects of different type. In an
array or arraylist, I want to store the information about which events I
added. Later, I want to process the arraylist and detach all the event
handlers. My problem is that I don't know which information to store. When
removing the handlers in a loop, the most important thing is that I don't
want to distinguish between the different object types and events, so I want
the code to be based on the basic Delegate/MulticastDelegate classes. I have
currently no clue how to do it. Something like:

dim o as new class1

addhandler o.ev1, addressof OnEv1
addhandler o.ev2, addressof OnEv2
...
for each i as Item in al 'al=arraylist, item=new class (see below)
removehandler i.???, i.???
next

Each time I use Addhandler I will create a new Item object and add it to the
arraylist. Though, I don't know what to store in an Item object. I thought
it must be a MulticastDelegate (the event) and a Delegate (the event
handler), but I am not able to store a reference to o.ev1 or o.ev2.

Is it possible at all or do I have to handle each event and object
individually? (btw, reflection is not an option) Thanks in advance.

Armin

Jul 9 '07 #1
1 1331
"Mudhead" <no*****@here.comschrieb im Newsbeitrag
news:OW**************@TK2MSFTNGP05.phx.gbl...
Look into EventHandlerList class

http://weblogs.asp.net/rosherove/arc...31/344773.aspx
Thanks for the link.

Meanwhile I found out that it is not possible what I was trying. The problem
is what's going on under the hood when adding/removing event handlers: The
AddHandler keyword doesn't expect an object as the first argument, but it's
the /name/ of an event. If it was an object, it would be possible to store a
reference. Everything done internally by executing Addhandler is specific to
the class and to the event. As it's specific, there is no multipurpose
solution that enables me storing references to events in the way intended.
Armin

Jul 11 '07 #2

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

Similar topics

9
by: Ravi Singh (UCSD) | last post by:
Hello all Attached is a simple HTML file that adds and delete rows. In the add row function I set an attribute "onClick" this triggers the testMessage() function. When I try this in Firefox it...
1
by: Henke | last post by:
Hi I have a aspx-page with a panel-control. On this panel control I add user controls dynamicly with LoadControl and panel.Controls.Add(myControl). On some of the dynamicly added user controls I...
8
by: Xero | last post by:
When my program is launched, there is a textbox on the form. When the user enters a character into the textbox (TextChanged), a second, declared textbox is added using this block of code. Dim...
5
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if...
6
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
6
by: Jake K | last post by:
Where is the best place to define event handlers? I need to define event handlers for a COM object referenced in my project and am doing so in the fowm load. Is this the best place?
8
by: jehugaleahsa | last post by:
Hello: I am creating a simple class library for simplifying reflection. I am creating an EventWrapper class that allows programmers to treat it like an event (minus the operator overloading)....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.