You do not know the circular relationship between modules in VB6.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.