var
    s:string;
   tfile:textfile;
beginopen1.Filter:='all files|*.*|*.txt|*.txt';
open1.Execute;
assignfile(tfile,open1.FileName);
  reset(tfile);
label1.Caption:=inttostr(filesize(tfile));
read(tfile,s);
 memo1.Text:=s;
 closefile(tfile);end;------------------------------------------------------------------------为什么上面的代码只能读出一行文本?????????????????谢谢

解决方案 »

  1.   

    With a type string variable:Read reads all characters up to, but not including, the next end-of-line er or until Eof(F) becomes True; it does not skip to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated.

    while not eof(tfile) begin
      read(tfile,s); 
      showmessage(s);
    end;
      

  2.   

    少了一句:
    After the first Read, each subsequent Read sees the end-of-line er and returns a zero-length string.
      

  3.   

    assignfile(tfile,open1.FileName);
      reset(tfile);
    label1.Caption:=inttostr(filesize(tfile));
    while not eof(tfile) do
    begin
     readln(tfile,s);
     memo1.lines.add(s);
    end;
     closefile(tfile);