在编写Arcgis Engine 过程中对于接口引用和实现过程过产生的感悟
Engine10.2版本
在vs里面新建类GeoMaoAO,并定义接口,在class中定义并实现,如下代码
以平时练习为例,我定义了一个接口,在里面定义了许多的控件,并在类中想要实现这一接口。如果在vs软件中将引用都配置好一般情况下是不会报错的。
1 //定义设置控件的接口 2 interface IComControl 3 { 4 //主视图控件 5 AxMapControl AxMapControl1 { get; set; } 6 //鹰眼视图控件 7 AxMapControl AxMapControl2 { get; set; } 8 //版面视图控件 9 AxPageLayoutControl AxPageLayoutControl1 { get; set; } 10 //定义设置颜色的方法 11 IRgbColor GetRGB(int r, int g, int b); 12 //TOOCControl控件 13 AxTOCControl AxTOCControl1 { get; set; } 14 } 15 class GeoMapAO : IComControl 16 { 17 AxTOCControl axTOCControl1; 18 public AxTOCControl AxTOCControl1 19 { 20 get { return axTOCControl1; } 21 set { axTOCControl1 = value;} 22 } 23 //实现地图控件的接口 24 AxMapControl axMapControl1; 25 public AxMapControl AxMapControl1 26 { 27 get { return axMapControl1; } 28 set { axMapControl1 = value;} 29 } 30 AxMapControl axMapControl2; 31 public AxMapControl AxMapControl2 32 { 33 get { return axMapControl2; } 34 set { axMapControl2 = value; } 35 } 36 AxPageLayoutControl axPageLayoutControl1; 37 public AxPageLayoutControl AxPageLayoutControl1 38 { 39 get { return axPageLayoutControl1; } 40 set { axPageLayoutControl1 = value; } 41 } 42 //定义实现获取RGB颜色的方法 43 public IRgbColor GetRGB(int r, int g, int b)//方法名字叫getRGB方法,用的时候即可复制整段public 44 { 45 IRgbColor pColor = new RgbColorClass(); 46 pColor.Red = r; 47 pColor.Green = g; 48 pColor.Blue = b; 49 return pColor; 50 } 51 }
以上代码,是没有问题的,但如果对方法里面的定义做些小改动,如18行中的
”public AxTOCControl AxTOCControl1“改成”public AxTOCControl AxTOCContrl1“,那我的系统在调试的时候就会报错
类的名字我起的是GeoMaoAO,接口IComControl无法被实现,是因为方法定义的句子产生错误,无法被引用,就导致此错误。
今天因为代码写得不够细致,在观察时没有仔细的去看,粗心导致了很多类似的错误,引用老师的一句话“电脑是不会骗人的,能骗倒你的只有你自己。”引以为戒,分享出来作为第一条博客。