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 ashcroftPosted Sep 4, 2007, 10:59 AM
Hello,
I found the error and it was what you described. The event handler assignment was in the wrong constructor. Thank you
AlanPosted Sep 3, 2007, 12:50 PM
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 ashcroftPosted Sep 3, 2007, 10:56 AM