1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
unit viewlog;
{$mode objfpc}
interface
uses
Classes, SysUtils, FileUtil
//, SynMemo
, SynEdit, LResources, Forms, Controls,
Graphics, Dialogs, StdCtrls;
type
{ TForm5 }
TForm5 = class(TForm)
SaveLog: TButton;
SynEdit1: TSynEdit;
procedure SaveLogClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form5: TForm5;
implementation
uses
dateutils
, Unit1
, appsettings //For saving and restoring hotkeys.
;
{ TForm5 }
{ Save log to a file. }
procedure TForm5.SaveLogClick(Sender: TObject);
var
OutFileName, LogString:String;
LogFilename: TextFile;
begin
//Save contents to standard logging area
OutFileName:=RemoveMultiSlash(
appsettings.LogsDirectory+
DirectorySeparator+
Format('log_%s.txt',
[FormatDateTime('yyyy-mm-dd_hhnnss', Now())]));
AssignFile(LogFilename,OutFileName);
try
Rewrite(LogFilename); //create the file
for LogString in SynEdit1.Lines do begin
Writeln(LogFilename, LogString);
end;
except
on E: Exception do
ShowMessage(
OutFileName+sLineBreak
+ 'Error: '+E.ClassName+sLineBreak
+ E.Message);
//MessageDlg('ERROR! IORESULT','ERROR! IORESULT: '
// + IntToStr(IOResult)
// + ' during LogCalButtonClick',mtWarning,[mbOK],0);
end;
CloseFile(LogFilename);
//Message about where log was saved to
MessageDlg('Log file stored in:' + sLineBreak + OutFileName, mtInformation,[mbOK],0);
end;
initialization
{$I viewlog.lrs}
end.
|