不想用Readln, 只想一次全部读完,里面包含完整的CRLF字符,我该怎么做?var 
   f:TextFile;
   str:AnsiString;
begin
        AssignFile(f,filename);
        Read(f,str) //出错!!!用readln没问题
        CloseFile(f)
end;

解决方案 »

  1.   

    while not Eof(f) do
          begin
            Read(f,str);
            memo1.lines.add(str);
           end;
         CloseFile(f);
      

  2.   

    先定义一个 TStringlist
    然后ts.loadformfile('....');
    然后str=ts.GetText大概就是这样子 自己多试试
      

  3.   

    如文件不大、建议先読入到内存(如:TStringList)procedure TForm1.Button1Click(Sender: TObject);
    var listfile : TStringList;
        filename: String;
        str:AnsiString;
    begin
      filename := ExtractFilePath (Application.ExeName) + 'UserFile.txt';
      listfile := TStringList.Create;
      try
        listfile.LoadFromFile(filename);
        str := listfile.Text;
        showMessage(str);
      finally
        listfile.Free;
      end;
    end;