当先锋百科网

首页 1 2 3 4 5 6 7
对象引用没有设置到对象实例的原因很多:
1、如下:
   public   int  Revise( ref  int  numline,  ref   int  numcircle,  ref   int  numtext,System.IO. StreamWriter  str_w,  List <  string  > record, EXT  extend, Line  [] lines,  Circle [] circles,  Text  [] texts)
        {
             string  [] record1 =record.ToArray();
             for  ( int  i = 0; i < record1.Length;i++ )
            {
                 string  temp =  string  .Empty;
                temp = record1[i];
                 if  (temp ==  "$EXTMIN"  )
                {
                    record1[i + 2] =  Convert  .ToString(extend.Min_x) ;
                    record1[i + 4] =  Convert  .ToString(extend.Min_y);
                    record1[i + 6] =  Convert  .ToString(extend.min_z);
                    record1[i + 10] =  Convert  .ToString(extend.Max_x);
                    record1[i + 12] =  Convert  .ToString(extend.Max_y);
                    record1[i + 14] =  Convert  .ToString(extend.Max_z);
                    i += 14;
                     continue  ;
                }
                 if  (temp ==  "AcDbLine"  )
                {
                    record1[i + 2]=  Convert  .ToString(lines[numline].x1);//此处开始报错
                    record1[i + 4] =  Convert  .ToString(lines[numline].y1);
                    record1[i + 6] =  Convert  .ToString(lines[numline].z1);
                    record1[i + 8] =  Convert  .ToString(lines[numline].x2);
                    record1[i + 10] =  Convert  .ToString(lines[numline].y2) ;
                    record1[i + 12] =  Convert  .ToString(lines[numline].z2);
                    numline--;
                    i += 12;
                     continue  ;
                }
            }

             for  ( int  i = 0; i < record1.Length;i++ )
            {
                str_w.WriteLine(record1[i]);
            }
             return  1;
        }
其中numline,numcircle,numtext,代表的line,circle,text对象的个数
原因就在于,数组的下标总是比个数小1,假如有5个元素,我们尝试给lines[5]赋值,而lines[5]已经越界,更不可能初始化。
2、对于数组,不光要实例化数组,还要实例化数组的对象
   public   int  Read_Entities( ref     int  numpolyline,  Polyline  [] plines, System.IO.  StreamReader  str_r)
        {
             string  buff =  string  .Empty;
            buff = str_r.ReadLine();
             //int numline = 0;
             //int numcircle = 0;
             //int numtext=0;
             while  (buff !=  "OBJECTS"  )
            {
              
                 if  (buff ==  "LWPOLYLINE"  )
                {
                     while  (buff !=  "AcDbPolyline"  )
                    {
                        buff = str_r.ReadLine();
                    }
                    plines[numpolyline] =  new   Polyline  ();//(1)
                    str_r.ReadLine();
                    plines[numpolyline].pointnum =  Convert  .ToInt32(str_r.ReadLine());
                    str_r.ReadLine();
                    str_r.ReadLine();
                    str_r.ReadLine();
                    str_r.ReadLine();
                    plines[numpolyline].points =  new   point  [plines[numpolyline].pointnum];//(2)
                     for  ( int  i=0;i<plines[numpolyline].pointnum;i++)
                    {
                        plines[numpolyline].points[i] =  new   point  ();//(3)
                        str_r.ReadLine();
                        plines[numpolyline].points[i].x =  Convert  .ToDouble(str_r.ReadLine());
                        str_r.ReadLine();
                        plines[numpolyline].points[i].y =  Convert  .ToDouble(str_r.ReadLine());
                    }

                }
                buff = str_r.ReadLine();
            }
             return  1;
        }
其中,多线由多个点组成
注释(1)处:初始化polyline对象
注释(2)处:初试化point数组
注释(3)处:初始化点对象实例
一直忘记了第二个,导致一直提示错误
待续。。。