What have I confused compiler with here?

C

Claire

The following is an extract from my base protocol class. It worked fine
until I changed my code so that each type of comms wll be handled by its own
protocol class.
I created a single Protocol abstract class and a couple of derived classes.
The delegate and event are declared in the base class as below.

// Base abstract Protocol class.
public abstract class Protocol : object
{
public delegate void ReceivedTourHandler(object sender,
BaseConverter.FileEventArgs e);
public event ReceivedTourHandler DoReceiveTourEvent;
}

// Derived class
public class DI225Protocol : Protocol
{
public MyFunc(void)
{
if (DoReceiveTourEvent != null) <<<< Error here "C The event
'Protocol.DoReceiveTourEvent' can only appear on the left hand side of +=
or -="
{
foo;
}
}
}

I'm also receiving a warning on the "public event ReceivedTourEvent "
declaration line that
"Protocol.cs(27): The event 'Protocol.DoReceiveTourEvent' is never used"
But in my CommunicationHandler object, this value is being used and is set
as follows

m_RapiDriver = new PPC_Driver();
m_RapiDriver.protocol.DoReceiveTourEvent += new
Protocol.ReceivedTourHandler(ReceiveHandler);

Any ideas what I'm doing wrong please?
Claire
 
C

Claire

Ive forgotten that event's can't be inherited in descendents. Added an
invoke method to do it.
Just wished the error messages were more intelligent than me!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Claire,

Just follow the guidelines, make a virtual method that handle the event ,
like this:

protected virtual OnEventName( DerivedEventArgs e)


Cheers,
 

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