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

Using an event defined in an interface

P: n/a
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.Posit ionUpdated

'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

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"sundog2000" <su********@gmail.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.