-
Notifications
You must be signed in to change notification settings - Fork 23
/
dialogsx.pas
executable file
·191 lines (176 loc) · 4.34 KB
/
dialogsx.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
unit dialogsx;
{$mode Delphi} //{$mode objfpc}
{$Include isgui.inc}
{$H+}
interface
uses
SysUtils,IniFiles;
{$IFNDEF GUI}
type
TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp);
TMsgDlgButtons = set of TMsgDlgBtn;
TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
{$ENDIF}
procedure Msg (lStr: string);
procedure ShowMsg (lStr: string);
procedure msgfx (a,b,c,d: double); overload; //fx used to help debugging - reports number values
//function MsgDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
function GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
function GetFloat(lStr: string; lMin,lDefault,lMax: single): single;
procedure MyReadLn;//no GUI: waits for user
function GetStr(lPrompt: string): string;
//procedure vx (a,b,c,d: double);
const
mrCancel = 2;
mrAbort = 1;// idAbort
mrNo = 0;
implementation
{$IFDEF GUI}uses
dialogs; {$ENDIF}
procedure vx (a,b,c,d: double); //vx used to help debugging - reports number values
begin
msg(floattostr(a)+':'+floattostr(b)+':'+floattostr(c)+':'+floattostr(d));
end;
procedure MyReadLn;
{$IFDEF GUI}
begin
//do nothing
end;
{$ELSE}
begin
{$IFNDEF UNIX}
if IsConsole then
ReadLn;
{$ENDIF}
end;
{$ENDIF}
function MsgDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
{$IFDEF GUI}
begin
result := 0;
ShowMsg('WARNING: MsgDlg not coded. Unabled to process this '+Msg);
{$ELSE}
begin
result := 0;
writeln('WARNING: dialogs not being used. Unabled to process this '+Msg);
{$ENDIF}
end;
procedure ShowMsg (lStr: string);
begin
{$IFDEF GUI}
ShowMessage(lStr); //if you get an error here - adjust isgui.inc
{$ELSE}
writeln(lStr)
{$ENDIF}
end;
procedure msgfx (a,b,c,d: double); overload; //fx used to help debugging - reports number values
begin
{$IFDEF GUI}
msg(floattostr(a)+'x'+floattostr(b)+'x'+floattostr(c)+'x'+floattostr(d));
{$ELSE}
msg(floattostr(a)+'x'+floattostr(b)+'x'+floattostr(c)+'x'+floattostr(d));
{$ENDIF}
end;
procedure Msg (lStr: string);
begin
{$IFDEF GUI}
Showmessage(lStr);
{$ELSE}
writeln(lStr)
{$ENDIF}
end;
function GetStr(lPrompt: string): string;
{$IFDEF GUI}
var
lOK: boolean;
begin
lOK := InputQuery(lPrompt, lPrompt, result);
if not lOK then
result := '';
end;
{$ELSE}
var
lS: string;
begin
writeln ( lPrompt);
readln(lS);
result := lS;
end;
{$ENDIF}
function GetFloat(lStr: string; lMin,lDefault,lMax: single): single;
{$IFDEF GUI}
var
s: string;
begin
s := floattostr(ldefault);
InputQuery('Integer required',lStr,s);
try
result := StrToFloat(S);
except
on Exception : EConvertError do
result := ldefault;
end;
if result < lmin then
result := lmin;
if result > lmax then
result := lmax;
end;
{$ELSE}
var
lS: string;
lError,lI: integer;
begin
writeln ( lStr+' ['+floattostr(lMin)+'..'+floattostr(lMax)+'], default '+floattostr(lDefault));
readln(lS);
Val(lS,lI,lError);
if lError = 0 then
result := (lI)
else begin
writeln(floattostr(lDefault));
result := lDefault;
end;
if result < lMin then
result := lMin;
if result > lMax then
result := lMax;
end;
{$ENDIF}
function GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
{$IFDEF GUI}
var
s: string;
begin
s := inttostr(ldefault);
InputQuery('Integer required',lStr,s);
try
result := StrToInt(S);
except
on Exception : EConvertError do
result := ldefault;
end;
if result < lmin then
result := lmin;
if result > lmax then
result := lmax;
end;
{$ELSE}
var
lS: string;
lError,lI: integer;
begin
writeln ( lStr+' ['+inttostr(lMin)+'..'+inttostr(lMax)+'], default '+inttostr(lDefault));
readln(lS);
Val(lS,lI,lError);
if lError = 0 then
result := round(lI)
else begin
writeln(inttostr(lDefault));
result := lDefault;
end;
if result < lMin then
result := lMin;
if result > lMax then
result := lMax;
end;
{$ENDIF}
end.