By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Inheriting events through COM - (VB.NET and VB6)

P: n/a
Helow, Good days.
I am creating a class Base in VB.NET, then I use this class base to
create to the class son across inherits, and Then generate the object
COM this class son to be used in VB6. The problem is that I do not
receive the events of the class base from VB6.

I show the code

----------------------------------------------------------------------------------------------------------------
Class Base - Name: A
----------------------------------------------------------------------------------------------------------------

Imports System.Runtime.InteropServices

' Delegate
<ComVisible(False)> _
Public Delegate Sub EventoAHandler(ByVal mensaje As String)

<InterfaceType(ComInterfaceType.InterfaceIsIUnknow n)> _
Public Interface Ia
Overloads Sub EventoA(ByVal Mensaje As String)
'overloaded
End Interface

'Indicamos que debe usar esta interface
<ComSourceInterfaces(GetType(Ia)), _
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class A

'Declaramos el evento puesto en la interface
Public Event EventoA As EventoAHandler

'Declaramos la funcion que emite este evento
Public Overridable Sub LanzarEvento()
RaiseEvent EventoA("Class A")
End Sub

'Declaramos otro evento
Public Sub LanzarEvento_A()
RaiseEvent EventoA("Se lanzo el evento de A")
End Sub

'Definimos una propiedad
Private m_Propiedad_A As Integer
Public Property Propiedad_A() As Integer
Get
Return m_Propiedad_A
End Get
Set(ByVal Value As Integer)
m_Propiedad_A = Value
End Set
End Property

'Definimos un Metodo
Public Function Ver_A() As Integer
Return m_Propiedad_A
End Function

End Class

----------------------------------------------------------------------------------------------------------------
Class Base - Name: B
----------------------------------------------------------------------------------------------------------------

Imports System.Runtime.InteropServices

<InterfaceType(ComInterfaceType.InterfaceIsIUnknow n)> _
Public Interface Ib
Inherits a.Ia
Sub EventoB(ByVal mensaje As String)
Sub EventaA_Sobreescrito(ByVal mensaje As String)
Shadows Sub EventoA(ByVal mensaje As String)
End Interface

'Indicamos que debe usar esta interface
<ClassInterface(ClassInterfaceType.AutoDual), _
ComSourceInterfaces(GetType(Ib))> _
Public Class B
Inherits a.A

'Delegate
<ComVisible(False)> Public Delegate Sub EventoBHandler(ByVal
Mensaje As String)
'<ComVisible(False)> Public Delegate Sub EventoAHandler(ByVal
mensaje As String)

'Declaramos el evento puesto en la interface
Public Event EventoB As EventoBHandler
Public Event EventaA_Sobreescrito As a.EventoAHandler
Public Shadows Event EventoA As a.EventoAHandler

'Declaramos la funcion que emite este evento
Public Overrides Sub LanzarEvento()
RaiseEvent EventoB("Class B")

End Sub

'Declaramos otro evento
Public Sub LanzarEvento_B()
RaiseEvent EventoB("Se lanzo el evento de B")
RaiseEvent EventoB(GetType(a.Ia).ToString)
End Sub

'Definimos una propiedad
Private m_Propiedad_B As Integer
Public Property Propiedad_B() As Integer
Get
Return m_Propiedad_B
End Get
Set(ByVal Value As Integer)
m_Propiedad_B = Value
End Set
End Property

'Definimos un Metodo
Public Function Ver_B() As Integer
Return m_Propiedad_B
End Function
Private Sub B_EventoA(ByVal mensaje As String) Handles
MyBase.EventoA
RaiseEvent EventoA("EventoA Capturado desde B y relanzado por
el EventoA Sombreado con 'Shadows': " & mensaje)
RaiseEvent EventoB("EventoA Capturado desde B y relanzado por
el EventoB" & mensaje)
End Sub
End Class

----------------------------------------------------------------------------------------------------------------
Form VB6
----------------------------------------------------------------------------------------------------------------

Private WithEvents o As B.B
Private Sub Form_Load()
Set o = New B.B
o.LanzarEvento
o.LanzarEvento_A ' I inherit the method that the eventoA throws but
I do not inherit the event

o.LanzarEvento_B
o.Propiedad_A = 1
o.Propiedad_B = 2
MsgBox o.Ver_A
MsgBox o.Ver_B

End Sub

Private Sub o_EventaA_Sobreescrito(ByVal mensaje As String)
MsgBox mensaje
End Sub

Private Sub o_EventoB(ByVal mensaje As String)
MsgBox mensaje
End Sub

Private Sub o_EventoA(ByVal mensaje As String)
MsgBox mensaje
End Sub

' Results: The object COM does not inherit the events of A
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

If somebody has some suggestion would thank for it.
Thank you very much and good luck, Damian

May 3 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.