Delphi TStreamWriter快速写入文件


本文整理自网络,侵删。

 
function InitLog(const FileName: string): TStreamWriter;
begin
  Result := TStreamWriter.Create(FileName, True);
  Result.AutoFlush := True;         // Flush automatically after write
  Result.NewLine := sLineBreak;     // Use system line breaks
end;

procedure CloseLog(const StreamWriter: TStreamWriter);
begin
  StreamWriter.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var 
  tTime : TDateTime;
  iBcl : Integer;
  LogSW: TStreamWriter;
  FileName: TFileName;
begin
  FileName := 'c:\Test.txt';
  LogSW := InitLog(FileName);
  try
    lbl1.Caption := 'Go->' + FileName; 
    lbl1.Refresh;
    tTime := Now;

    For iBcl := 0 to 2000 do
      LogSW.WriteLine(IntToStr(ibcl) + '   ' +  'lkjlkjlkjlkjlkjlkjlkj');

    lbl1.Caption  :=  FormatDateTime('sss:zzz',Now - tTime);
  finally
    CloseLog(LogSW);
  end;
end;

相关阅读 >>

Delphi 提取字符串中所有数字

Delphi winapi: flashwindow - 闪烁窗口

Delphi for 循环 to和downto的理解

Delphi 链接转换为本地文件路径

Delphi webbroker iis cgi 的配置

Delphi d10.x 安卓app开发中创建密钥库文件

Delphi资源文件的详细使用方法

Delphi treeview添加背景图片

Delphi xe3中如何crc验证函数?

Delphi 2009 之 tcategorypanelgroup[2]: headeralignment、gradientdirection

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...