Circular Reference Between Modules when 2 Class Modules Listen to Each others Events 
Author Message
 Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

I created two collection classes that I want to keep synchronized. When an
item is added to one collection class, an event is raised so the other
collection adds the same item . The problem is that declaring module level
variables in each collection class to listen for events in the mirror
collection class produces the error "Circular References Between Modules."

Can someone please help?



Wed, 02 Jun 2004 06:22:53 GMT  
 Circular Reference Between Modules when 2 Class Modules Listen to Each others Events
There are a handful of ways to stop circular references being a problem
(usualy by creating
a "weak" reference - a reference that is obtained without incrementing the
objects refcount)
but because you are referencing these WithEvents, I don't think these will
work as VB actually
places an internally generated object in between to marshall the events

One possible way to do what you are doing is to use another object to
marshall the change
information via proxy
ie
Proxy :
    has a single method "Changed" which accepts whatever infortmation you
want to pass
    has an event with similar information in it's signature
Both of these (method and event) also pass the a reference to the object
that changed for
reeasons that will become clear
CollectionA holds a WithEvents ref to Proxy
CollectionB holds a WithEvents ref to Proxy

When CollectionA changes, it calls the Proxy.Changed method passing in the
appropriate information
Proxy responds by raising the event
Now both CollectionA and CollectionB will receive this event.  This is why
the "source"
object is passed..the the event handler can determine that it was the
source, and casn so ignore it

So..when CollectionA handles the event, it notices that it was the source
and ignores it
But when CollectionB handles the event, it can handle it appropriately

HTH
--
Chris Anderson
(aka Merak on VISBAS-L)


Quote:
> I created two collection classes that I want to keep synchronized. When an
> item is added to one collection class, an event is raised so the other
> collection adds the same item . The problem is that declaring module level
> variables in each collection class to listen for events in the mirror
> collection class produces the error "Circular References Between Modules."

> Can someone please help?



Thu, 03 Jun 2004 12:15:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

2. Class modules 97 - Refering to array within a custom class module

3. Accessing procedures of a class module from another class module

4. Class Module and Module

5. Class Modules & Modules

6. VB Modules/Class Modules

7. class module vs. module

8. modules and class modules

9. Returning the name of a module/class module

10. Modules or Class modules?

11. Q(VB5) : Different between module & class module

12. Q: Code Module vs UserControl (Form, Class) module.

 

 
Powered by phpBB® Forum Software