读取文本文件的字符串添加到Memo中及相反

procedure TForm1.Button1Click(Sender: TObject);
var
  txt:TextFile;
  s:string;
  path:string;
begin
  path:=ExtractFilePath(Application.ExeName);
  AssignFile(txt,path+'\test.txt');

  Reset(txt);   //读打开文件,文件指针移到首
  Memo1.Clear;

  while not Eof(txt) do
  begin
    Readln(txt,s);
    Memo1.Lines.Add(s);
  end;

  CloseFile(txt);
end;

 

procedure TForm1.Btn2Click(Sender: TObject);
var
  OutputFile: TextFile;
  s: string;
  i: Integer;
begin
  AssignFile(OutputFile, 'D:\ciske_c.txt');
  Rewrite(OutputFile);

  for I := 0 to Mmo1.Lines.Count-1 do
  begin
    Writeln(OutputFile, Mmo1.Lines.Strings[i]);
  end;

  CloseFile(OutputFile);
end;

 

posted @ 2013-02-26 10:14  林燃  阅读(186)  评论(0编辑  收藏  举报