问题描述
我正在尝试在VB6应用程序中使用我的COM类。我做了一些包装纸。当我创建对象时,我看到消息Is nothing 1
,因此它表明已设置成员变量并且它不为null,但是当我尝试使用属性返回该成员时,则在返回行中看到异常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(...)
解决方法
将方法更改为此:
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
Set MyImplementation = m_myComClass
End Property
为清楚起见,您错过了Set