返回时未设置错误对象变量或块变量 属性
Error Object variable or with block variable not set while returning property
我正在尝试在 VB6 应用程序中使用我的 COM class。我做了某种包装纸。当我创建对象时,我看到消息 Is Nothing 1
,所以它表明成员变量已设置并且它不为空,但是当我尝试 return 这个成员使用 属性,然后在 return 行我看到异常 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
我正在尝试在 VB6 应用程序中使用我的 COM class。我做了某种包装纸。当我创建对象时,我看到消息 Is Nothing 1
,所以它表明成员变量已设置并且它不为空,但是当我尝试 return 这个成员使用 属性,然后在 return 行我看到异常 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