T
Terry
I have made up a contrived example show the problem I am having. I have some
ReadOnly interfaces:
Public Interface IROPerson
ReadOnly Property FirstName() As String
ReadOnly Property LastName() As String
ReadOnly Property Friends() As IROPersons
End Interface
Public Interface IROPersons
Function Count() As Integer
Function GetEnumerator() As System.Collections.IEnumerator
Function Item(ByVal Index As Integer) As IROPerson
End Interface
On the project Assembly page, I have checked "Make Com Visible". All is
fine so far.
In a new Project, I define the R/W versions. Won't bother you with the
Person class, but here is the 'Persons' class:
Public Class Persons
Implements System.Collections.IEnumerable
Implements ROInterfaces.IROPersons
Private _Persons As New System.Collections.Generic.List(Of Person)
Public Sub Add(ByVal p As Person)
_Persons.Add(p)
End Sub
Public Function Item(ByVal Index As Integer) As Person
Return _Persons(Index)
End Function
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements _
System.Collections.IEnumerable.GetEnumerator, _
ROInterfaces.IROPersons.GetEnumerator
Return _Persons.GetEnumerator
End Function
Public Function Count() As Integer Implements
ROInterfaces.IROPersons.Count
Return _Persons.Count
End Function
Public Function Item1(ByVal Index As Integer) As ROInterfaces.IROPerson
Implements _
ROInterfaces.IROPersons.Item
Return Item(Index)
End Function
End Class
Still so good so far.
I then have a 'Wrapper' then instanciates 'People' who derive from Person.
The wrapper hands back to the 'client' (VB6, VBA, .Net) an IROPerson
reference to a 'Person'.
No problem with a .Net client, but a VB6 client can not 'enumerate' the
'Friends' list of the 'Person'. It's visible, it can go through it with
For...Next Loop but it can't use a For...Each loop.
I have discovered by trial and error, that if I make the "Persons" class a
com class, it works! The client still holds no reference to the com visible
"Persons" class, but somehow this makes 'enumeration' work in the client.
So my question is .... Why?
ReadOnly interfaces:
Public Interface IROPerson
ReadOnly Property FirstName() As String
ReadOnly Property LastName() As String
ReadOnly Property Friends() As IROPersons
End Interface
Public Interface IROPersons
Function Count() As Integer
Function GetEnumerator() As System.Collections.IEnumerator
Function Item(ByVal Index As Integer) As IROPerson
End Interface
On the project Assembly page, I have checked "Make Com Visible". All is
fine so far.
In a new Project, I define the R/W versions. Won't bother you with the
Person class, but here is the 'Persons' class:
Public Class Persons
Implements System.Collections.IEnumerable
Implements ROInterfaces.IROPersons
Private _Persons As New System.Collections.Generic.List(Of Person)
Public Sub Add(ByVal p As Person)
_Persons.Add(p)
End Sub
Public Function Item(ByVal Index As Integer) As Person
Return _Persons(Index)
End Function
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements _
System.Collections.IEnumerable.GetEnumerator, _
ROInterfaces.IROPersons.GetEnumerator
Return _Persons.GetEnumerator
End Function
Public Function Count() As Integer Implements
ROInterfaces.IROPersons.Count
Return _Persons.Count
End Function
Public Function Item1(ByVal Index As Integer) As ROInterfaces.IROPerson
Implements _
ROInterfaces.IROPersons.Item
Return Item(Index)
End Function
End Class
Still so good so far.
I then have a 'Wrapper' then instanciates 'People' who derive from Person.
The wrapper hands back to the 'client' (VB6, VBA, .Net) an IROPerson
reference to a 'Person'.
No problem with a .Net client, but a VB6 client can not 'enumerate' the
'Friends' list of the 'Person'. It's visible, it can go through it with
For...Next Loop but it can't use a For...Each loop.
I have discovered by trial and error, that if I make the "Persons" class a
com class, it works! The client still holds no reference to the com visible
"Persons" class, but somehow this makes 'enumeration' work in the client.
So my question is .... Why?