File: viewlog.pas

package info (click to toggle)
udm 1.0.0.352-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,076 kB
  • sloc: pascal: 72,496; ansic: 6,892; awk: 880; makefile: 768; sh: 493; perl: 34; python: 22; tcl: 18
file content (81 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download
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.