delphi 字符串保存为 TXT文件  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.031605005264282 seconds