-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathJPL.Dialogs.pas
225 lines (188 loc) · 5.88 KB
/
JPL.Dialogs.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
unit JPL.Dialogs;
{$I .\..\jp.inc}
{$IFDEF FPC}{$MODE OBJFPC}{$H+}{$ENDIF}
interface
uses
SysUtils, Types, Graphics, {$IFDEF DELPHIXE2_OR_ABOVE}System.UITypes,{$ENDIF}
Forms, Dialogs, Controls, StdCtrls;
type
TWinStrParams = record
FormCaption: string;
FormWidth: integer;
FormHeight: integer;
FormColor: TColor;
MemoText: string;
MemoBgColor: TColor;
MemoFontName: string;
MemoFontSize: integer;
MemoFontColor: TColor;
MemoMarginLeft: integer;
MemoMarginRight: integer;
MemoMarginTop: integer;
MemoMarginBottom: integer;
MemoHideScrollbars: Boolean;
//EscExit: Boolean;
end;
procedure ShowMsg(const Text: string; DlgType: TMsgDlgType = mtInformation; Buttons: TMsgDlgButtons = [mbOK]; HelpContext: integer = 0);
procedure Msg(const Text: string);
procedure MsgInfo(const Text: string);
procedure MsgWarning(const Text: string);
procedure MsgError(const Text: string);
procedure MsgInt(const x: Int64);
procedure MsgStrVal(const Text: string; const x: Int64; TextSuffix: string = ' = '); overload; // string + integer msg
procedure MsgStrVal(const Text: string; const x: Extended; TextSuffix: string = ' = '; FormatStr: string = '0.0000'); overload; // string + float msg
procedure MsgFloat(x: Extended; FormatStr: string = '0.0000');
function ShowWinStr(const MemoText: string; Caption: string = ''; Width: integer = 500; Height: integer = 400; MemoFontName: string = 'Consolas'; MemoFontSize: integer = 9): string; overload;
function ShowWinStr(WinStrParams: TWinStrParams; UseDefaultMargins: Boolean = True): string; overload;
procedure MsgBool(const b: Boolean; TrueStr: string = 'True'; FalseStr: string = 'False');
procedure MsgBoolYN(const b: Boolean);
procedure MsgBoolTF(const b: Boolean);
implementation
uses
JPL.Strings;
procedure MsgBool(const b: Boolean; TrueStr: string = 'True'; FalseStr: string = 'False');
begin
if b then Msg(TrueStr) else Msg(FalseStr);
end;
procedure MsgBoolTF(const b: Boolean);
begin
MsgBool(b, 'True', 'False');
end;
procedure MsgBoolYN(const b: Boolean);
begin
MsgBool(b, 'Yes', 'No');
end;
function ShowWinStr(WinStrParams: TWinStrParams; UseDefaultMargins: Boolean = True): string; overload;
var
Form: TForm;
Memo: TMemo;
begin
Form := TForm.Create(nil);
Memo := TMemo.Create(Form);
Form.Constraints.MinHeight := 100;
Form.Constraints.MinWidth := 200;
if WinStrParams.MemoHideScrollbars then Memo.ScrollBars := ssNone
else Memo.ScrollBars := ssBoth;
Memo.Parent := Form;
if UseDefaultMargins then
begin
WinStrParams.MemoMarginLeft := 3;
WinStrParams.MemoMarginRight := 3;
WinStrParams.MemoMarginTop := 3;
WinStrParams.MemoMarginBottom := 3;
end;
try
Memo.Text := WinStrParams.MemoText;
Memo.Font.Size := WinStrParams.MemoFontSize;
Memo.Font.Name := WinStrParams.MemoFontName;
Memo.Font.Color := WinStrParams.MemoFontColor;
Memo.Color := WinStrParams.MemoBgColor;
Memo.BorderStyle := bsNone;
{$IFDEF DCC}
Memo.Margins.Left := WinStrParams.MemoMarginLeft;
Memo.Margins.Right := WinStrParams.MemoMarginRight;
Memo.Margins.Top := WinStrParams.MemoMarginTop;
Memo.Margins.Bottom := WinStrParams.MemoMarginBottom;
Memo.AlignWithMargins := True;
{$ENDIF}
Memo.Align := alClient;
//Form.FormStyle := fsStayOnTop;
Form.BorderIcons := [biSystemMenu];
Form.Caption := WinStrParams.FormCaption;
Form.Width := WinStrParams.FormWidth;
Form.Height := WinStrParams.FormHeight;
Form.Color := WinStrParams.FormColor;
Form.Position := poOwnerFormCenter;
Memo.Align := alClient;
Form.Repaint;
Form.ShowModal;
finally
Result := Memo.Text;
Form.Free;
end;
end;
function ShowWinStr(const MemoText: string; Caption: string = ''; Width: integer = 500; Height: integer = 400; MemoFontName: string = 'Consolas'; MemoFontSize: integer = 9): string; overload;
var
Form: TForm;
Memo: TMemo;
{$IFDEF DELPHI2009_OR_BELOW}
Arr: TStringDynArray;
{$ELSE}
Arr: {$IFDEF FPC}specialize{$ENDIF} TArray<string>;
{$ENDIF}
s: string;
i: integer;
begin
if Pos('|', MemoFontName) > 0 then
begin
SplitStrToArray(MemoFontName, Arr, '|');
for i := 0 to High(Arr) do
begin
s := Arr[i];
if Screen.Fonts.IndexOf(s) > 0 then
begin
MemoFontName := s;
Break;
end;
end;
end;
Form := TForm.Create(nil);
Memo := TMemo.Create(Form);
Memo.ScrollBars := ssBoth;
Memo.Parent := Form;
try
Memo.Align := alClient;
Memo.Text := MemoText;
Memo.Font.Size := MemoFontSize;
Memo.Font.Name := MemoFontName;
Memo.ScrollBars := ssVertical;
Form.FormStyle := fsStayOnTop;
Form.BorderIcons := [biSystemMenu];
Form.Caption := Caption;
Form.Width := Width;
Form.Height := Height;
Form.Position := poOwnerFormCenter;
Form.Repaint;
Form.ShowModal;
finally
Result := Memo.Text;
Form.Free;
end;
end;
procedure ShowMsg(const Text: string; DlgType: TMsgDlgType = mtInformation; Buttons: TMsgDlgButtons = [mbOK]; HelpContext: integer = 0);
begin
MessageDlg(Text, DlgType, Buttons, HelpContext);
end;
procedure Msg(const Text: string);
begin
ShowMsg(Text, mtCustom, [mbOK]);
end;
procedure MsgInfo(const Text: string);
begin
ShowMsg(Text, mtInformation, [mbOK]);
end;
procedure MsgWarning(const Text: string);
begin
ShowMsg(Text, mtWarning, [mbOK]);
end;
procedure MsgError(const Text: string);
begin
ShowMsg(Text, mtError, [mbOK]);
end;
procedure MsgInt(const x: Int64);
begin
Msg(IntToStr(x));
end;
procedure MsgStrVal(const Text: string; const x: Int64; TextSuffix: string = ' = ');
begin
Msg(Text + TextSuffix + IntToStr(x));
end;
procedure MsgFloat(x: Extended; FormatStr: string = '0.0000');
begin
Msg(FormatFloat(FormatStr, x));
end;
procedure MsgStrVal(const Text: string; const x: Extended; TextSuffix: string = ' = '; FormatStr: string = '0.0000');
begin
Msg(Text + TextSuffix + FormatFloat(FormatStr, x));
end;
end.