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;
字符串保存为 TXT文件
最新推荐文章于 2019-12-19 11:14:20 发布