Objects in Collection and Raise Events 
Author Message
 Objects in Collection and Raise Events

I have read the archives on dejanews and I'm still not sure, so I
thought I'd ask this (in vb.general.discussion and in vb.com):

I have a COM object (in an ActiveX DLL).  It raises events with
RaiseEvent.

I have a standard exe with a collection of that object.  The object was
dimmed WithEvents.  The collection cannot be dimmed with events.  I am
passing an arg on the event which is a key to the collection.

In debug, the RaiseEvent in the class module executes OK, no errors.
But the event handler in the form module never gets entered.

MSDN didn't mention this being a problem that I could find.  I read the
news archives and it looked like I was trying something that can't be
done. So....

I changed the com object to do callbacks instead of raise events:

I moved all of the code which handles the collection from the standard
exe form into a private class in the same project.  In that class the
former event handlers are now public methods, thus part (the only part)
of the default interface.  In the original object (for the collection),
there are two changes:

1) It has a new property of type "object" - to be set for the callbacks.

2) It doesn't RaiseEvent anymore - it says "Call newproperty.Method
(args, etc)"

And also back in the private class of the standard exe, I set the
newproperty to "Me" in every brand new object.

This all seems to work, though I am going to do some more thorough
testing.

But did I need to do it?  Was there an easier way?  Can you RaiseEvents
from objects in collections and I was just missing something about why
I wasn't receiving the events in the original version?

And finally, how about RaiseEvents from objects in arrays?

Thanks in advance,  C

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 06 Jan 2003 03:00:00 GMT  
 Objects in Collection and Raise Events

No you can't use Dim WithEvents for Arrays or collections of objects.
WithEvents are a 1:1 mapping. You could dim a withevent for a collection
class (your own class that has a collection internally). Your code might be
cleaner if you have a collection class handle the callback administration
with it's members, if wanted you could RaiseEvents from the collection
class.

Anyhow I would recommend using callbacks since these are a lot faster and
more flexible then events. I usually make special interfaces for CB
functions which I implement in whatever object or class that needs it.

With CB's watch out for circular references...

Greetings,

Joppe

Quote:

> I have read the archives on dejanews and I'm still not sure, so I
> thought I'd ask this (in vb.general.discussion and in vb.com):

> I have a COM object (in an ActiveX DLL).  It raises events with
> RaiseEvent.

> I have a standard exe with a collection of that object.  The object was
> dimmed WithEvents.  The collection cannot be dimmed with events.  I am
> passing an arg on the event which is a key to the collection.

> In debug, the RaiseEvent in the class module executes OK, no errors.
> But the event handler in the form module never gets entered.

> MSDN didn't mention this being a problem that I could find.  I read the
> news archives and it looked like I was trying something that can't be
> done. So....

> I changed the com object to do callbacks instead of raise events:

> I moved all of the code which handles the collection from the standard
> exe form into a private class in the same project.  In that class the
> former event handlers are now public methods, thus part (the only part)
> of the default interface.  In the original object (for the collection),
> there are two changes:

> 1) It has a new property of type "object" - to be set for the callbacks.

> 2) It doesn't RaiseEvent anymore - it says "Call newproperty.Method
> (args, etc)"

> And also back in the private class of the standard exe, I set the
> newproperty to "Me" in every brand new object.

> This all seems to work, though I am going to do some more thorough
> testing.

> But did I need to do it?  Was there an easier way?  Can you RaiseEvents
> from objects in collections and I was just missing something about why
> I wasn't receiving the events in the original version?

> And finally, how about RaiseEvents from objects in arrays?

> Thanks in advance,  C

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 06 Jan 2003 03:00:00 GMT  
 Objects in Collection and Raise Events
Look at the collections section of VB Vision
(http://www.mvps.org/vbvision/). Or use the weCollection class that you can
download (source code) from my site.

--
Eduardo A. Morcillo
http://www.domaindlx.com/e_morcillo

Quote:

> I have read the archives on dejanews and I'm still not sure, so I
> thought I'd ask this (in vb.general.discussion and in vb.com):

> I have a COM object (in an ActiveX DLL).  It raises events with
> RaiseEvent.

> I have a standard exe with a collection of that object.  The object was
> dimmed WithEvents.  The collection cannot be dimmed with events.  I am
> passing an arg on the event which is a key to the collection.

> In debug, the RaiseEvent in the class module executes OK, no errors.
> But the event handler in the form module never gets entered.

> MSDN didn't mention this being a problem that I could find.  I read the
> news archives and it looked like I was trying something that can't be
> done. So....

> I changed the com object to do callbacks instead of raise events:

> I moved all of the code which handles the collection from the standard
> exe form into a private class in the same project.  In that class the
> former event handlers are now public methods, thus part (the only part)
> of the default interface.  In the original object (for the collection),
> there are two changes:

> 1) It has a new property of type "object" - to be set for the callbacks.

> 2) It doesn't RaiseEvent anymore - it says "Call newproperty.Method
> (args, etc)"

> And also back in the private class of the standard exe, I set the
> newproperty to "Me" in every brand new object.

> This all seems to work, though I am going to do some more thorough
> testing.

> But did I need to do it?  Was there an easier way?  Can you RaiseEvents
> from objects in collections and I was just missing something about why
> I wasn't receiving the events in the original version?

> And finally, how about RaiseEvents from objects in arrays?

> Thanks in advance,  C

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 06 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Raising events from objects in a collection

2. Raising events from objects in a collection

3. Raising events from objects in a collection

4. Raising events from collection member objects?!?!

5. Raising events from objects in a collection???

6. Raising events from objects in a collection???

7. Raising events from objects in a collection???

8. Raising events from objects in a collection???

9. Raising events from objects in a collection???

10. Raising events from objects in a collection???

11. Raising events from a class within a collection class

12. Raise event from Collection member??

 

 
Powered by phpBB® Forum Software