Events

M

Martin Brindle

Can anyone answer this?

Image a class, let's call it A, that that has a timer. The timer times out
and calls an event, called E, to all the delegates it has attached to
it.With me so far?. Now image another class, called B, which inherits from A
and overrides the timer event so it can implement it own variation. How do i
get the event E, that's also called in class B's timer function, to bubble
up it's events to the base class or register them with class B? The compiler
insists that only events A can be registered in A.

Am i missing something?
 
A

AlanT

Martin said:
Can anyone answer this?

Image a class, let's call it A, that that has a timer. The timer times out
and calls an event, called E, to all the delegates it has attached to
it.With me so far?. Now image another class, called B, which inherits from A
and overrides the timer event so it can implement it own variation. How do i
get the event E, that's also called in class B's timer function, to bubble
up it's events to the base class or register them with class B? The compiler
insists that only events A can be registered in A.

Am i missing something?


If I read this correctly, you wish to raise a base class event from a
derived class.
If so, you might try this


public class BaseA
{

public MyEventHandler MyEventE;

public delegate void MyEventHandler(object sender, MyEventArgs e);

public class MyEventArgs {
}

protected void RaiseEventE(MyEventArgs e){
MyEventE(this,e);
}

}


public class DerivedB {

public sub Something() {
RaiseEventE(new MyEventArgs());
}

}



The derived class does not have access to the event directly but can
call the protected member to raise the event.


hth,
Alan.
 

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