2017-02-17

【Delphi】寫純文字檔型式 log

  1.  
  2. procedure txtlog(str: string);
  3. const
  4. sLogPath = 'C:\mylog.txt';
  5. var
  6. logfile : TextFile;
  7. begin
  8. if not FileExists(sLogPath) then
  9. begin
  10. AssignFile(logfile, sLogPath);
  11. ReWrite(logfile);
  12. CloseFile(logfile);
  13. end;
  14. AssignFile(logfile, sLogPath);
  15. Append(logfile);
  16. Writeln(logfile, FormatDateTime('yyyy/mm/dd HH:nn:ss',now)+': '+str);
  17. Flush(logfile);
  18. CloseFile(logfile);
  19. end;
  20.