Dim objClass2 As Class2 Private Sub Class_Initialize() Set objClass2 = New Class2 Private Sub Class_Terminate() 在Class2中添加如下的代码: Dim objClass1 As Class1 Public Property Set Class1(ByRef NewValue As Class1) Private Sub Class_Initialize() Private Sub Class_Terminate()
为了能看看这一方面的范例,可以建立一个标准的EXE VB工程。添加两个类模块,Class1 和 Class2,在Class1中添加如下的代码:
Debug.Print TypeName(Me) & ".Initialize"
Set objClass2.Class1 = Me
End Sub
Set objClass2 = Nothing
Debug.Print TypeName(Me) & ".Terminate"
End Sub
Set objClass1 = NewValue
End Property
Debug.Print TypeName(Me) & ".Initialize"
End Sub
Set objClass1 = Nothing
Debug.Print TypeName(Me) & ".Terminate"
End Sub