
Engine10.2版本
在vs里面新建类GeoMaoAO,并定义接口,在class中定义并实现,如下代码
以平时练习为例,我定义了一个接口,在里面定义了许多的控件,并在类中想要实现这一接口。如果在vs软件中将引用都配置好一般情况下是不会报错的。
//定义设置控件的接口
interface IComControl
{
//主视图控件
AxMapControl AxMapControl1 { get; set; }
//鹰眼视图控件
AxMapControl AxMapControl2 { get; set; }
//版面视图控件
AxPageLayoutControl AxPageLayoutControl1 { get; set; }
//定义设置颜色的方法
IRgbColor GetRGB(int r, int g, int b);
//TOOCControl控件
AxTOCControl AxTOCControl1 { get; set; }
}
class GeoMapAO : IComControl
{
AxTOCControl axTOCControl1;
public AxTOCControl AxTOCControl1
{
get { return axTOCControl1; }
set { axTOCControl1 = value;}
}
//实现地图控件的接口
AxMapControl axMapControl1;
public AxMapControl AxMapControl1
{
get { return axMapControl1; }
set { axMapControl1 = value;}
}
AxMapControl axMapControl2;
public AxMapControl AxMapControl2
{
get { return axMapControl2; }
set { axMapControl2 = value; }
}
AxPageLayoutControl axPageLayoutControl1;
public AxPageLayoutControl AxPageLayoutControl1
{
get { return axPageLayoutControl1; }
set { axPageLayoutControl1 = value; }
}
//定义实现获取RGB颜色的方法
public IRgbColor GetRGB(int r, int g, int b)//方法名字叫getRGB方法,用的时候即可复制整段public
{
IRgbColor pColor = new RgbColorClass();
pColor.Red = r;
pColor.Green = g;
pColor.Blue = b;
return pColor;
}
}
以上代码,是没有问题的,但如果对方法里面的定义做些小改动,如18行中的
”public AxTOCControl AxTOCControl1“改成”public AxTOCControl AxTOCContrl1“,那我的系统在调试的时候就会报错
类的名字我起的是GeoMaoAO,接口IComControl无法被实现,是因为方法定义的句子产生错误,无法被引用,就导致此错误。
今天因为代码写得不够细致,在观察时没有仔细的去看,粗心导致了很多类似的错误,引用老师的一句话“电脑是不会骗人的,能骗倒你的只有你自己。”引以为戒,分享出来作为第一条博客。