From: Karl King - TP Technologies <kking TPTECHNOLOGIES.COM>
>Is is possible to raise an event within a collection
class ?
Well, sure. That's rather ordinary.
But what I think you mean is, is it possible to raise an
event
from within a *member* of a collection class, and actually
have someone receive that event?
The answer again is yes. In fact, in dotNet there are
several
ways to do it.
The way that also worked in VB6 is indirect.
* Collection owner has collection, and also has a proxy
object.
* Each member of the collection has a reference to the proxy
object.
* Collection member calls a method of the proxy object,
which
raises the event. (The specific member involved is probably
a
parameter to the method call and the event.)
* Collection owner receives event from proxy object.
In VB.Net you don't have to worry about circular
references,
so you can just hand the collection member a reference to
the
collection class and have it call methods - which may raise
events
if that's what you need.
Another .Net option is Delegates. This basically lets you
hand
the collection member a reference to a *method* in some
object
(such as the owner of the collection), and the member can
then
call this method. (It's even legal for a class to grant
access to
its own private methods via Delegates. Somehow that makes me
feel a bit twitchy... how do I know that the collection
member
isn't passing this access around?)
And yet another is AddHandler. This basically says that THIS
method of THIS object will handle THAT event of THAT object
-
and it's object-specific, at run time.
===================================
This list is hosted by DevelopMentorŪ http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
|