【发布时间】:2021-01-16 10:59:13
【问题描述】:
我正在尝试在 VB6 应用程序中使用我的 COM 类。我做了某种包装。当我创建对象时,我看到消息Is Nothing 1,因此它表明已设置成员变量并且它不为空,但是当我尝试使用属性返回此成员时,然后在返回行中我看到异常Object variable or with block variable not set。我不知道如何解决它。
// MyComClass
This is a COM class with method Operation
// clsMyCom.cls
Private WithEvents m_myComClass As MyComClass
Private Sub Class_Initialize()
If m_myComClass Is Nothing Then
MsgBox "Is Nothing 1"
End If
Set m_myComClass = New MyComClass
If m_myComClass Is Nothing Then
MsgBox "Is Nothing 2"
End If
End Sub
Public Property Get MyImplementation() As MyComClass
If m_myComClass Is Nothing Then
MsgBox "Is Nothing 3"
End If
// in this line I see exception:
// object variable or with block variable not set
MyImplementation = m_myComClass
End Property
// usage
Dim variable As clsMyCom
Set variable = New clsMyCom
Call variable.MyImplementation.Operation(...)
【问题讨论】: