Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/vb6/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Com 返回属性时未设置对象变量或with block变量时出错_Com_Vb6 - Fatal编程技术网

Com 返回属性时未设置对象变量或with block变量时出错

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

我正在尝试在VB6应用程序中使用COM类。我做了一些包装纸。当我创建对象时,我看到消息
为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