-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMessages.pas
96 lines (81 loc) · 2.71 KB
/
Messages.pas
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
Copyright (c) Peter Karpov 2010 - 2018.
Usage of the works is permitted provided that this instrument is retained with
the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
}
{$IFDEF FPC} {$MODE DELPHI} {$ENDIF}
unit Messages; //////////////////////////////////////////////////////////////////////
{
>> Version: 0.1
> Description
Unit responsible for displaying text messages
>> Author
Peter Karpov
Email : [email protected]
Homepage : inversed.ru
GitHub : inversed-ru
Twitter : @inversed_ru
>> Changelog
0.1 : 2018.09.18 ~ FreePascal compatibility
+ Routine comments
0.0 : 2011.03.19 + Initial version
Notation: + added, - removed, * fixed, ~ changed
}
interface ///////////////////////////////////////////////////////////////////////////
uses
Problem;
const
ErrorOpenFile = 'Failed to open ';
ErrorUndefined = 'Undefined routine';
MsgNewBest = 'New best score: ';
MsgRunStarted = '{} run {} started';
MsgRunFinished = ' run finished';
type
ProcMessage = procedure(
const S : AnsiString);
// Display a message S via ShowMessage if the latter is not nil
procedure TryShowMessage(
const S : AnsiString;
ShowMessage : ProcMessage);
// Display a message S with error tag prepended via ShowMessage
// if the latter is not nil
procedure ShowError(
const S : AnsiString;
ShowMessage : ProcMessage);
// Display a message with NewBest's score via ShowMessage
// if the latter is not nil
procedure ShowNewBestScore(
const NewBest : TSolution;
ShowMessage : ProcMessage);
implementation //////////////////////////////////////////////////////////////////////
uses
InvSys;
// Display a message S via ShowMessage if the latter is not nil
procedure TryShowMessage(
const S : AnsiString;
ShowMessage : ProcMessage);
begin
if @ShowMessage <> nil then
ShowMessage(S);
end;
// Display a message S with error tag prepended via ShowMessage
// if the latter is not nil
procedure ShowError(
const S : AnsiString;
ShowMessage : ProcMessage);
const
ErrorTag = 'ERROR: ';
begin
if @ShowMessage <> nil then
ShowMessage(ErrorTag + S);
end;
// Display a message with NewBest's score via ShowMessage
// if the latter is not nil
procedure ShowNewBestScore(
const NewBest : TSolution;
ShowMessage : ProcMessage);
begin
TryShowMessage(MsgNewBest + FormatScore(NewBest.Score), ShowMessage);
end;
end.