I have the delegate definition
public delegate void OnServingSelectedEvent(object sender, decimal Serving);
class FractionDecimalTextBox:SourceGrid.Cells.Editors.TextBox
{
public event OnServingSelectedEvent OnServingSelected;
public override bool ApplyEdit()
{
OnServingSelected(this, Generals.ToDecimal(Control.Text));
return base.ApplyEdit();
}
}
I keep getting the error
Object reference not set to an instance of an object.
With
Cannot obtain value of local or argument '
shown in the watch page.
As far as I understand it, this is supposed to point to the current object, but I keep getting this error, although it is completely unregular as I have another class where it works great. Does anyone know what I am doing wrong?

brian ashcroft5 reputationPosted Sep 3, 2007, 6:56 AM EDT
AlanRank #669 · 3.6K reputationPosted Sep 3, 2007, 8:50 AM EDT
Generally, when firing my own events, I check that the event delegate is not null i.e. at least one handler has been added to its invocation list:
public override bool ApplyEdit()
{
if (OnServingSelected != null)
OnServingSelected(this, Generals.ToDecimal(Control.Text));
return base.ApplyEdit();
}
Other than that I can't see anything wrong with the code.
brian ashcroft5 reputationPosted Sep 4, 2007, 6:59 AM EDT
Hello,
I found the error and it was what you described. The event handler assignment was in the wrong constructor. Thank you