Delphi将字符串写入text文档

来源:互联网 发布:大疆 知乎 编辑:程序博客网 时间:2024/06/06 23:54
procedure TForm1.Button1Click(Sender: TObject);
var
  afile: TFileStream;
begin
  if not FileExists('c:\a.txt') then
  begin
    try
      afile := TFileStream.Create('c:\a.txt', fmCreate);
      afile.WriteBuffer(PChar(Edit1.Text + #13#10)^, Length(Edit1.Text + #13#10));
    finally
      afile.Free;
    end;
  end
  else begin
    try
      afile := TFileStream.Create('c:\a.txt', fmOpenWrite);
      afile.Seek(0, soEnd);
      afile.WriteBuffer(PChar(Edit1.Text + #13#10)^, Length(Edit1.Text + #13#10));
    finally
      afile.Free;
    end;
  end;
end;
0 0
原创粉丝点击