Link to home
Start Free TrialLog in
Avatar of andreas_rafn
andreas_rafnFlag for Denmark

asked on

How to catch events of objects in a collection in VBA?

I have defined an class - lets call it SomeClass - with a range of different events.
In order to create a functionality for storing and handling batches of these classes, I have also created a collection class - lets call it SomeClassCollection. Within this the SomeClass objects are stored in a collection.

I would really like to be able to catch the events of individual SomeClass objects in the collection. And let the SomeClassCollection object act accordingly (e.g. by raising its own event). Is this in any way possible?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andreas_rafn

ASKER

Not a bad idea, did not think of that myself. Regarding performance, I guess that adding a parent will not affect performance much as long as it is passed as a reference. How can I assure that? Is it as simple as adding the ByRef keyword to the set property, e.g.:

Public Property Set Parent(ByRef ParentToSet as SomeObjectCollection)
   Set mParent = ParentToSet 
End Property

Open in new window

If you pass an object ByVal you only pass a copy of the pointer, not a copy of the object, so I'm not sure how that would affect performance but using ByRef should work.