Using an event defined in an interface

S

sundog2000

I am writing my first VB.net program and I am struggling to figure out
how to attach an event to a method, when the event is part of an
interface that the class implements.

I have declared a delegate function, a public event, and the class
object (g_pFeedManager) is first dim'ed as an interface. Later it is
new'd at a class that implements that interface. However, when I try
to call AddHandler to attach the event to a function, I have problems.
It doesn't recognize the event as being part of the class - actually
the error says it doesn't recognize it as part of the interface that it
was originally dim'ed as.

This program uses ArcGIS libraries, but I think the problem is my
knowledge of the language not a characterstic of the libraries. Here
is some relevant code:

'The delegate function
Public Delegate Sub PositionUpdatedEventHandler(ByVal position As
ESRI.ArcGIS.Carto.esriGpsPositionInfo, ByVal estimate As Boolean)

'The event
Public Event PositionUpdated As PositionUpdatedEventHandler
'Implements
ESRI.ArcGIS.Carto.IRealTimeFeedManagerEvents.PositionUpdated

'Dimming the object as an interface
Public g_pFeedManager As ESRI.ArcGIS.Carto.IRealTimeFeedManager

'in a later function, allocating memory for the object.
g_pFeedManager = New ESRI.ArcGIS.Carto.RealTimeFeedManager

'This function gives the error.
'error BC30676: 'PositionUpdated' is not an event of
'ESRI.ArcGIS.Carto.IRealTimeFeedManager'.
AddHandler g_pFeedManager.PositionUpdated, AddressOf OnPositionChange

**
So I don't know how to refer to the event. I tried setting up a test
case just like this:
Dim test As ESRI.ArcGIS.Carto.IRealTimeFeedManagerEvents
AddHandler test.PositionUpdated, AddressOf OnPositionChange
So test is definitely of the proper type and the error message is:
error BC30676: 'PositionUpdated' is not an event of
'ESRI.ArcGIS.Carto.IRealTimeFeedManagerEvents'.

Although clearly it is of the correct type, it still gives me this
error.

Any ideas?
Thanks,
Nick
 
H

Herfried K. Wagner [MVP]

sundog2000 said:
I am writing my first VB.net program and I am struggling to figure out
how to attach an event to a method, when the event is part of an
interface that the class implements.

\\\
Public Interface IFoo
Event Goo(ByVal sender As Object, ByVal e As EventArgs)
End Interface

Public Class Sample
Implements IFoo

Public Event Goo( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Implements IFoo.Goo

Public Sub Test()
RaiseEvent Goo(Me, EventArgs.Empty)
End Sub
End Class
..
..
..
Dim f As IFoo = New Sample
AddHandler f.Goo, AddressOf Me.Sample_Goo
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top