E
Eric T.
I’ve got a class B that has delegates for users to hook up to.
class B
{
public delegate void KeyHandler (object sender, EventArgs e);
public virtual event KeyHandler OnKey;
....
Internally, in method F, I might do:
if (OnKey != null)
OnKey(this, whatever);
....
}
Now I want to derive from this class, and call it D. I still want the user
to hook to the delegate, but some of the derived features need access to it
as well. How do I do that? I tried the following (note the virtual on the
event in the base-class):
class D : B
{
public override event KeyHandler OnKey;
.... Internally, in method FF, I might do:
if (OnKey != null)
OnKey(this, whatever);
....
}
The user then connects as follows:
D od = new D();
od.OnKey += new KeyHandler(some function X);
When method FF executes, the function X is called, but when method F is
called (in the base class), it thinks OnKey is null, and X is not called.
F needs to call X as well... I’m not allowed to access the OnKey event from
a derived class into a base-class, I get an error message: B.OnKey' can only
appear on the left hand side of += or -= (except when used from within the
type 'B').
Any suggests are most welcome!
class B
{
public delegate void KeyHandler (object sender, EventArgs e);
public virtual event KeyHandler OnKey;
....
Internally, in method F, I might do:
if (OnKey != null)
OnKey(this, whatever);
....
}
Now I want to derive from this class, and call it D. I still want the user
to hook to the delegate, but some of the derived features need access to it
as well. How do I do that? I tried the following (note the virtual on the
event in the base-class):
class D : B
{
public override event KeyHandler OnKey;
.... Internally, in method FF, I might do:
if (OnKey != null)
OnKey(this, whatever);
....
}
The user then connects as follows:
D od = new D();
od.OnKey += new KeyHandler(some function X);
When method FF executes, the function X is called, but when method F is
called (in the base class), it thinks OnKey is null, and X is not called.
F needs to call X as well... I’m not allowed to access the OnKey event from
a derived class into a base-class, I get an error message: B.OnKey' can only
appear on the left hand side of += or -= (except when used from within the
type 'B').
Any suggests are most welcome!