delphi 字符串保存为 TXT文件


本文整理自网络,侵删。

 

procedure TForm1.Timer1Timer(Sender: TObject);
var
    afile:   TFileStream;
    //DateTime : TDateTime;
    str,da,StrToWrite : string;


begin
    //DateTime := Time;  // store the current date and time
    str := TimeToStr(Time); // convert the time into a string
    da:= DateToStr(Date);
    StrToWrite:=  da+'  '+str   +   #13#10; //  #13#10 回车 换行

    if   not   FileExists( 'c:/a.txt ')   then
    begin
        try
            afile   :=   TFileStream.Create( 'c:/a.txt ',   fmCreate);
            afile.WriteBuffer(PChar(StrToWrite)^,Length(StrToWrite));
        finally
            afile.Free;
        end;
    end
    else   begin
        try
            afile   :=   TFileStream.Create( 'c:/a.txt ',   fmOpenWrite);
            afile.Seek(0,   soEnd);
            afile.WriteBuffer(PChar(StrToWrite)^,Length(StrToWrite));
        finally
            afile.Free;
        end;
    end;
end;

相关阅读 >>

Delphi listview 导出excel txt vcf 单元

Delphi 的按位运算详解

Delphi xe10 fdmemtable 数据保存本地和从本地加载

Delphi webbrowser控件实现对ie浏览器的各种控制

Delphi doc转txt

Delphi rect()

Delphi 取bmp图片宽高

Delphi sysutils.stringreplace - 替换

Delphi xe5 使用 android 内置函数几个小测试

Delphi_关于null,nil

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



打赏

取消

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

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

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

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

评论

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