Today, my brother found an interesting phenomenon when debugging the program. The system prompts "circular relationship between modules". Let's look at the sample code below:
'CD
Option explicit
Public event clickevent ()
Public withevents C as CE
Public sub click ()
Raiseevent clickevent
End sub
Private sub c_clickevent ()
'
End sub
'Ce
Option explicit
Public event clickevent ()
Public withevents C as CD
Public sub click ()
Raiseevent clickevent
End sub
Private sub c_clickevent ()
'
End sub
In fact, there are no errors in the use of class CD and Ce. The key is the problem of VB6 itself. There are two classes with events that can be referenced by each other, but they cannot be used, if you remove any c_clickevent system, it will be okay.
Later, we adopted the circular proxy method and added a proxy as the intermediary. The system still prompts this.
The final solution is to add only one container class and coordinate the work of the two classes through the container class. The solution is as follows: 'Ca
Option explicit
Public event clickevent ()
Public sub click ()
Raiseevent clickevent
End sub
'Cb
Option explicit
Public event clickevent ()
Public sub click ()
Raiseevent clickevent
End sub
'Ccontainer
Option explicit
Public withevents A as CA
Public withevents B as CB
Private sub a_clickevent ()
B. Click
End sub
Private sub B _clickevent ()
A. Click
End sub