有段代码看不明白。大侠帮忙看看

goodb515344oy 2008-11-05 03:50:36
我在单击btnAdd的时候,出现了错误。提示说_Insertting为空。为什么会这样能?
要怎么改这段代码?

private void btnAdd_Click(object sender, EventArgs e)
{
int Index=1;
double x, y;
OnInsertPoint(Index, x, y);
}
private void OnInsertPoint(int index, double x, double y)
{
FlightPoint point = new FlightPoint();
point.X = x;
point.Y = y;
FlightPointCollectionEventArgs e = new FlightPointCollectionEventArgs(index, point, null);
_Insertting(this, e);
}
private FlightPointCollectionEventHandler _Insertting;
public event FlightPointCollectionEventHandler Insertting
{
add
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Combine(_Insertting, value);
}
remove
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Remove(_Insertting, value);
}
}
public delegate void FlightPointCollectionEventHandler(object sender,
FlightPointCollectionEventArgs e);
...全文
164 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
dlmeijianyu 2008-11-06
  • 打赏
  • 举报
回复
顶下。
gogogo 2008-11-06
  • 打赏
  • 举报
回复
改成我12楼的代码
goodb515344oy 2008-11-06
  • 打赏
  • 举报
回复
gogogo
我就是不知道_Insertting 要怎么用,为什么是null的,我试过用两个testbox给x,y输入数值;
int index = 1;
int x, y;
x = int.Parse(txtLong.Text);
y = int.Parse(txtLat.Text);
OnInsertPoint(index, x, y);
但是还是不行,运行到 _Insertting(this, e)就出错了, _Insertting为null.
要如何让 _Insertting(this, e)不会出错呢??
gogogo 2008-11-05
  • 打赏
  • 举报
回复
private void btnAdd_Click(object sender, EventArgs e) 
{
int Index=1;
double x, y;
if(_Insertting != null)
OnInsertPoint(Index, x, y);
}

或者这么改
花落_ 2008-11-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 gogogo 的回复:]
C# code public event FlightPointCollectionEventHandler Insertting
{
add
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Combine(_Insertting, value);
}
remove
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Remove(_Insertting, value);
}

[/Quote]
支持
hangang7403 2008-11-05
  • 打赏
  • 举报
回复
ding
killer_liqiao 2008-11-05
  • 打赏
  • 举报
回复
up
zccmy22 2008-11-05
  • 打赏
  • 举报
回复
恩。入参给值。看一下。
starts_2000 2008-11-05
  • 打赏
  • 举报
回复

private void OnInsertPoint(int index, double x, double y)
{
FlightPoint point = new FlightPoint();
point.X = x;
point.Y = y;
FlightPointCollectionEventArgs e = new FlightPointCollectionEventArgs(index, point, null);
if(_Insertting ! = null)
_Insertting(this, e);
}

gogogo 2008-11-05
  • 打赏
  • 举报
回复
        public event FlightPointCollectionEventHandler Insertting 
{
add
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Combine(_Insertting, value);
}
remove
{
_Insertting = (FlightPointCollectionEventHandler)Delegate.Remove(_Insertting, value);
}


这句应该是属性Insertting 的定义,外部没有对Insertting 赋值就先调用了OnInsertPoint方法,所以出错
j1a2b3c 2008-11-05
  • 打赏
  • 举报
回复
是不是没有订阅事件?
文飞扬 2008-11-05
  • 打赏
  • 举报
回复

private void btnAdd_Click(object sender, EventArgs e)
{
int Index=1;
double x, y;
OnInsertPoint(Index, x, y); //这里没有对变量xy赋值啊,肯定出错了
}
xxyping 2008-11-05
  • 打赏
  • 举报
回复
你那里面有很多的方法都没贴出来,看的不怎么明白,自己设个段点慢慢的看看吧
贫僧又回来了 2008-11-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 feiyun0112 的回复:]
Insertting(this, e);


*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
[/Quote]
只有引用的内容不允许回复!!
feiyun0112 2008-11-05
  • 打赏
  • 举报
回复
Insertting(this, e);


*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧