Delphi实用小function

时间:2021-10-10 09:52:13

Write Log

    // strLog : the log content need write to log file;

    // strFile: the compliete file path(include the file name) of the log file. e.g. C:\log.log;

    procedure WriteLog(strLog, strFile: string);

    var

       fLog: TextFile;

    begin

       AssignFile(fLog, strFile);

       try

          if FileExists(strFile) then

            Append(fLog)

         else

            Rewrite(fLog);

    

         //ready to write log content

         Writeln(fLog,Format('%s -> %s', [FormatDateTime('hh:mm:ss',now()), strLog]) );

      finally

         CloseFile(fLog);

      end;

   end;