473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using an event defined in an interface

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
1 4424
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild....
1
by: Liz | last post by:
As a newbie I have been trying to set up an event handler in my user-defined control to trigger an event in my form when lblSelectedClient.Text changes. I get an error on my event definition...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
3
by: Brett Hall | last post by:
I have a VB.NET interface that my managed C++ code is to implement. I seem to be stuck implementing an event defined in that interface. Does anyone have a simple code snippet that will show me...
4
by: Anthony Yott | last post by:
Anyone have an example of defining a custom event (i.e custom delegate) in an interface? -- Anthony Yott
6
by: keith.thornhill | last post by:
hi all, lets say i have a usercontrol which implements a custom interface. like so: ------------------------------------------------- interface IMyInterface sub buttonClick() end interface
4
by: Mani | last post by:
Hi All, Can anyone please tell me how interface is going to help me in real time senarios. As interface contains only skeleton of methos and it has to be inherited to a class. Is there...
1
by: Mayur | last post by:
This is my COM wrapper written in c#. using System.Runtime.InteropServices; namespace SAFE_NAMESPACE_NAME { #region Events raised by your COM class public delegate void Event1Handler(int i,...
3
by: =?Utf-8?B?TkVXMi5ORVQ=?= | last post by:
I have a static event declared in a C++ ref class, that can then be handled in a VB app. I'm trying to expose the static event through the interface that the C++ ref class implements so the VB app...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.