简体   繁体   English

使用Interop将对象数组从VB6返回到VB.NET

[英]Return array of objects from VB6 to VB.NET using Interop

I'm making a COM dll in .NET for use in VB6, the dll works fine in VB6. 我正在.NET中制作一个COM dll以在VB6中使用,该dll在VB6中工作正常。

but I have a problem when I want to assign arrays. 但是我想分配数组时遇到问题。

here is the Person class in VB.NET, the Name property is an array of the class called Class2 这是VB.NET中的Person类, Name属性是一个名为Class2的类的数组

Public Class Person

  Private _name() As Class2

  Public Property Name() As Class2()
     Get
       Return Me._name
     End Get
     Set
       Me._name = value
     End Set
  End Property

End Class

This is the Class2 : 这是Class2

Public Class Class2

  Private m_id As String

  Public Property id() As String
    Get
      Return m_id
    End Get
    Set
      m_id = Value
    End Set
  End Property

End Class

this is the code I'm using in VB6: 这是我在VB6中使用的代码:

Dim vArray(2) As MyLib.Class2
vArray(0).id = "Hello 1"
vArray(1).id = "Hello 2"
vArray(2).id = "Hello 3"

Dim i As New MyLib.Person
i.Name = vArray ' here throws an error

Try 尝试

 Dim vArray(2) As Class2
        For index = 0 To vArray.Length - 1
            vArray(index) = New Class2
            vArray(index).id = "Hello " + index.ToString
        Next
        Dim i As New Person
        i.Name = vArray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM