為了能看看這一方面的范例,可以建立一個(gè)標(biāo)準(zhǔn)的EXE VB工程。添加兩個(gè)類模塊,Class1 和 Class2,在Class1中添加如下的代碼:
Dim objClass2 As Class2
Private Sub Class_Initialize()
Debug.Print TypeName(Me) & ".Initialize"
Set objClass2 = New Class2
Set objClass2.Class1 = Me
End Sub
Private Sub Class_Terminate()
Set objClass2 = Nothing
Debug.Print TypeName(Me) & ".Terminate"
End Sub
在Class2中添加如下的代碼:
Dim objClass1 As Class1
Public Property Set Class1(ByRef NewValue As Class1)
Set objClass1 = NewValue
End Property
Private Sub Class_Initialize()
Debug.Print TypeName(Me) & ".Initialize"
End Sub
Private Sub Class_Terminate()
Set objClass1 = Nothing
Debug.Print TypeName(Me) & ".Terminate"
End Sub