var
  f:TextFile;
  headpnt,endpnt:Tpoint;
  kind:string;
  data1:TData;
  color:TColor;
  SepChar:string;///////////////////////////////////////////////////////////////////////////
Readln(f,kind,SepChar,headpnt.x,SepChar,headpnt.y,SepChar,endpnt.x,SepChar,endpnt.y,SepChar,data1.DataBaseName,SepChar,data1.TableName,SepChar,data1.FieldName,SepChar,data1.Key,SepChar,color,SepChar);
我这样读出来的各变量的类型没改变吧?那我下边要用到除了SepChar外的各量,直接应用可以不?不知道我表诉清楚没

解决方案 »

  1.   

    Readln  你知道Read出来的是个什么样类型的数据吗 中间的参数必须为字符窜类型的也就是说你前面定义的var
      f:TextFile;
      headpnt,endpnt:Tpoint;
      kind:string;
      data1:TData;
      color:TColor;
      SepChar:string;只要类型不是string类型的都需要转换
      

  2.   

    Readln每次读出一行文本字符按你的要求要用BlockRead来按字节读
    var
      f:TextFile;
      headpnt,endpnt:Tpoint;
      kind:string[255]; //必须定义字段长度
      data1:TData;
      color:TColor;
      SepChar:string[255];
    //////////
    begin
    ...
    ...
    BlockRead(f,kind,length(kind)); //读string
    BlockRead(f,headpnt,sizeof(headpnt)) //读其他类型
    ...
    ...
    end
      

  3.   

    谢谢!我明白了,我在书上没查到转换颜色的,可以这样转换颜色吗?
    color:=strtoint(ss[10]);
    SS是我读到的串
      

  4.   

    我的文件是这样的格式
    backcolor1.bmp
    seRectangle 74 100 114 140 null null null null 65280 
    seEchelon 246 143 286 183 null null null null 65280 
    seRectangle 136 54 176 94 null null null null 65280 
    seDiamond 210 60 250 100 null null null null 65280 不可以这样读是吧?
    BlockRead(f,kind,length(kind)); //读string
    BlockRead(f,headpnt,sizeof(headpnt)) //读其他类型
    ...
    ...
      

  5.   

    关键看你写入文件的格式
    你这样的格式虽然用文本编辑器打开很直观,但对程序来说不是很方便
    每读一行就要做分析,效率太低了
    建议直接把需要的内容做成record形式,读写都很方便
    例如
    type
     TfileInf=record
        filename:string[255];
        headpnt,endpnt:Tpoint;
        kind:string[255]; //必须定义字段长度
        data1:TData;
        color:TColor;
        SepChar:string[255];
     end使用
    //写文件
    var
     F:File;
     fileInf:TfileInf;
    begin
     //录入信息
     fileInf.filename='backcolor1.bmp';
     fileInf.headpnt=Point(0,0);
     ...
     ...
     //写入
     AssignFile(F, 'C:\test.dat');
     Rewrite(F);
     BlockWrite(F, fileInf, sizeof(fileInf));
     CloseFile(F);
    end;//读出
    var
     F:File;
     fileInf:TfileInf;
    begin
     AssignFile(F, 'C:\test.dat');
     Reset(F);
     BlockRead(F, fileInf, sizeof(fileInf));
     CloseFile(F); showmessage(fileInf.filename);
    end;
      

  6.   

    谢谢你宝贵的建议,但我导师指定让我这样做的,文本文件读出来还要画出相应的图形,连接数据库。我读的时候总有超出边界的错误,我怀疑我读的有问题,我刚接触DELPHI不久,好多东西还不太了解,谢谢你的指点!