Com 返回属性时未设置对象变量或with block变量时出错
我正在尝试在VB6应用程序中使用COM类。我做了一些包装纸。当我创建对象时,我看到消息Com 返回属性时未设置对象变量或with block变量时出错,com,vb6,Com,Vb6,我正在尝试在VB6应用程序中使用COM类。我做了一些包装纸。当我创建对象时,我看到消息为Nothing 1,因此它建议设置了成员变量且该变量不为null,但当我尝试使用属性返回此成员时,在返回行中我看到异常对象变量或未设置块变量。我不知道如何修理它 // MyComClass This is a COM class with method Operation // clsMyCom.cls Private WithEvents m_myComClass As MyComClass Priva
为Nothing 1
,因此它建议设置了成员变量且该变量不为null,但当我尝试使用属性返回此成员时,在返回行中我看到异常对象变量或未设置块变量
。我不知道如何修理它
// 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
为了清楚起见,您错过了
设置
将方法更改为:
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
需要说明的是,您错过了
集合当返回对象时,我不知道属性
中需要集合
。MyImplementation=
指定对象的默认属性(如果有),例如MyImplementation.Text=“some string”
。错误“需要对象…”意味着MyImplementation
在尝试分配给其默认属性时是Nothing
。我不知道返回对象时property
中需要Set
。MyImplementation=
分配给对象的默认属性(如果有),例如MyImplementation.Text=“some string”
。错误“Object required…”表示MyImplementation
在尝试分配给其默认属性时为Nothing
。