我有一个类模块 MyVBAclass,它有一个自定义 COM 类的成员
Private mMyCOMclass As MyCOMclass
Public Property Get InnerClass() As MyCOMclass
Set InnerClass = mMyCOMclass
End Property
Public Property Let InnerClass(value As MyCOMclass)
Set mMyCOMclass = value
End Property
Private Sub Class_Initialize()
Set mMyCOMclass = New MyCOMclass
End Sub
MyCOMclass 实现了 Clone() 和 CopyTo() 方法,Clone 返回 MyCOMclass 的新实例,CopyTo 只是将属性复制到已经初始化的对象。这是我遇到的问题,如果有人能解释如何避免它,那就太好了。
Dim MyVBAinstance As MyVBAclass
Set MyVBAinstance = New MyVBAclass
Dim COMinstance As MyCOMclass, copyOfCOM As MyCOMclass
Set COMinstance = New MyCOMclass
Set copyOfCOM = New MyCOMclass
' Do some stuff with COMinstance
Call COMinstance.CopyTo(copyOfCOM) ' Works fine
MyVBAinstance.InnerClass = COMinstance.Clone() ' Works fine even without Set
Call COMinstance.CopyTo(MyVBAinstance.InnerClass) ' DOESN'T WORK