比如一个文件内容:xxx
{
   id    1212     //this is id
   name  sadhasd
   age   22
}把xxx读出,并且读{}内的内容,每行2个字段。其中"//"为注释不读请问有没有好的或者现成的算法或控件去实现?

解决方案 »

  1.   

    Txxx = packed record
      ID :integer;
      Name :string;
      Age :Byte;
    end;procedure ReadxxxFile(const filename :string);
    var
      DataFile :File of Txxx;
      xxx :Txxx;
    begin
      AssignFile(DataFile, filename);
      Reset(DataFile);
      try
        if not EOF(DataFile) then
          read(DataFile, xxx);
      finally
        CloseFile(DataFile);
      end;
    end;
      

  2.   

    用TStringlistvar
      SL: TStringlist;
    begin
      SL := TStringlist.Create;
      try
        SL.Loadfromfile('D:\你的文件');
        //SL[0]就是第二行的内容,sl[1]第二行的容,SL.text就是整个文件的内容
        //写已写代码处理你想要的
      finally
        SL.free;
      end;
    end;