Repository navigation
Expand file tree
/
Copy pathdiagnostics.dpr
More file actions
82 lines (72 loc) · 1.75 KB
/
Copy pathdiagnostics.dpr
File metadata and controls
82 lines (72 loc) · 1.75 KB
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
82
program diagnostics;
uses
System.SysUtils, System.Classes, Moon.Diagnostics;
type
TConfigWorker = class(TThread)
protected
procedure Execute; override;
end;
procedure ApplicationData(Report: TDiagnosticReport);
begin
Report.Add('operation', 'diagnostic example');
{ Report.AttachFile('application.log'); }
end;
procedure ExampleFailure;
begin
raise Exception.Create('Example of a caught exception');
end;
procedure ReadMissingConfig;
var
Stream: TFileStream;
begin
{ The executable is a file, so it cannot contain settings.ini. }
Stream := TFileStream.Create(ParamStr(0) + PathDelim + 'settings.ini', fmOpenRead);
Stream.Free;
end;
procedure TConfigWorker.Execute;
begin
ReadMissingConfig;
end;
procedure RunWorker;
var
Worker: TConfigWorker;
begin
Worker := TConfigWorker.Create(True);
try
Worker.Start;
Worker.WaitFor;
WriteLn('Worker exception: ', Worker.FatalException.ClassName);
finally
Worker.Free;
end;
end;
procedure ReadFirstItem;
var
Items: TStringList;
begin
Items := TStringList.Create;
try
WriteLn(Items[0]);
finally
Items.Free;
end;
end;
var
Mode: string;
begin
InitializeReports('reports', ApplicationData);
Mode := ParamStr(1);
If Mode = 'conversion' then WriteLn(StrToInt('invalid amount'))
else If Mode = 'file' then ReadMissingConfig
else If Mode = 'collection' then ReadFirstItem
else If Mode = 'arithmetic' then WriteLn(100 div StrToInt(ParamStr(2)))
else If Mode = 'worker' then RunWorker
else If Mode = '' then begin
try
ExampleFailure;
except
WriteLn(WriteExceptionReport('caught by the application'));
end;
WriteLn(WriteManualReport('all current threads'));
end else raise Exception.Create('Unknown diagnostics mode: ' + Mode);
end.