Store added event handlers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

.



Relevant Pages

  • Re: CListBox items color
    ... all the associated handlers for starters and store some information ... (in the item's lParam value perhaps) ...
    (microsoft.public.vc.language)
  • Re: Global variable
    ... startup and store this value in variable so that I can use it within my ... whole app. ... Is your problem where/how to store the handlers or how to get those ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Format datagrid columns
    ... but when I push the next button the procedure DataGridCard is ... AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev ... Probaly handlers the next also the itemcommand, ... >> you stored in the buttons commandName, ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Format datagrid columns
    ... but when I push the next button the procedure DataGridCard is ... AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev ... Probaly handlers the next also the itemcommand, ... >> you stored in the buttons commandName, ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: AddHandler / RemoveHandler
    ... I normally reserve RemoveHandler for the object that called AddHandler. ... For example if I call AddHandler in the Add method of a custom collection, ... handlers, even handlers it did not add... ...
    (microsoft.public.dotnet.framework)