假如我有一个test.txt文档
内容如下:
——————————————
Loving you
is easy 'Cos you're beautiful
loving you
is all I want to do
Loving you
is more that
Just a dream come true
And everthing I do
is out of loving you
La La...Doo un doo un doo doo, Ah...
——————————————请问我怎样通过delphi来把文本里面的内容按行,一行一行地写到memo里面去

解决方案 »

  1.   

    Memo1.Lines.LoadFromFile('driver:\path\test.txt');
      

  2.   

    呵呵,Memo本身就有LoadFromFile方法你真想一行一行读么?
      

  3.   

    如果真要一行一行的读就这么写吧:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      F: TextFile;
      sFName, sText: String;
    begin
      sFName := 'e:\test.txt';
      if Not FileExists(sFName) then  exit;
      try
        AssignFile(F,sFName);
        Reset(F);
        Memo1.Clear;
        while Not Eof(F) Do
        begin
          ReadLn(F,sText);
          Memo1.Lines.Add(sText);
        end;
      finally
        CloseFile(F);
      end;
    end;