source: trunk/Components/ACLDialogs.pas@ 210

Last change on this file since 210 was 210, checked in by RBRi, 18 years ago

using StringUtilsUnit

  • Property svn:eol-style set to native
File size: 10.4 KB
Line 
1Unit ACLDialogs;
2// A variety of useful message box functions, including displaying
3// lists. They all allow specification of a caption.
4
5 Interface
6
7Uses
8 Classes,
9{$ifdef os2}
10 ACLMessageForm
11{$else}
12 Controls,
13 MessageFormWin
14{$endif}
15 ;
16
17// Shows a message box
18Procedure DoMessageDlg( Caption: String;
19 Message: string );
20
21// Shows an error message box
22Procedure DoErrorDlg( Caption: String;
23 Message: string );
24
25// Shows a warning message box
26Procedure DoWarningDlg( Caption: String;
27 Message: string );
28
29// Shows a long message box
30Procedure DoLongMessageDlg( Caption: String;
31 Message: PChar );
32
33// Shows a dialog with OK and cancel buttons
34// Returns true if OK pressed
35Function DoConfirmDlg( Caption: string;
36 Message: string ): boolean;
37
38// Returns true if confirmation given.
39Function DoConfirmListDlg( Caption: string;
40 Message: string;
41 List: TStrings ): boolean;
42
43// Shows a message containing a list
44Procedure DoMessageListDlg( Caption: string;
45 Message: string;
46 List: TStrings );
47
48// Shows an error message containing a list
49Procedure DoErrorListDlg( Caption: string;
50 Message: string;
51 List: TStrings );
52
53// Returns true if yes is clicked
54Function DoYesNoListDlg( Caption: string;
55 Message: string;
56 List: TStrings ): boolean;
57
58// Returns true if yes is clicked
59Function DoYesNoDlg( Caption: string;
60 Message: string ): boolean;
61
62// Shows a message containing a list
63// with a help callback for items in the list
64Procedure DoMessageListHelpDlg( Caption: string;
65 Message: string;
66 List: TStrings;
67 ListHelpCallback: TListHelpCallback );
68
69{$ifdef os2}
70Function DoInputQuery( Const ACaption: String;
71 Const APrompt: String;
72 Var Value: String ): Boolean;
73
74{$endif}
75
76Implementation
77
78uses
79 SysUtils,
80 Forms,
81 Dialogs,
82 StdCtrls,
83 Buttons,
84{$ifdef os2}
85 ACLLanguageUnit, ControlsUtility,
86{$endif}
87 CharUtilsUnit;
88
89// -------------------------------------------------
90
91Function DoACLDialog( const Caption: string;
92 const Message: string;
93 const List: TStrings;
94 const ShowCancel: boolean;
95 const IconType: TMessageIconType;
96 const ShowHelp: boolean;
97 const UseYesNo: boolean;
98 const ListHelpCallBack: TListHelpCallBack ): TModalResult;
99var
100 TheDialog: TMessageForm;
101 PMessage: PChar;
102Begin
103 TheDialog := TMessageForm.Create( nil );
104 TheDialog.Caption := Caption;
105 PMessage := NewPCharAsCopyOfStr(Message);
106 TheDialog.TheText := PMessage;
107
108 TheDialog.ShowCancel := ShowCancel;
109 TheDialog.IconType := IconType;
110 TheDialog.ShowHelp := ShowHelp;
111 TheDialog.UseYesNo := UseYesNo;
112 TheDialog.ListHelpCallBack := ListHelpCallBack;
113
114 if List <> nil then
115 begin
116 TheDialog.ShowList := true;
117 TheDialog.ListBox.Items.Assign( List );
118 end
119 else
120 begin
121 TheDialog.ShowList := false;
122 end;
123
124 Result := TheDialog.ShowModal;
125
126 TheDialog.Destroy;
127 StrDispose( PMessage );
128end;
129
130Procedure DoMessageListDlg( Caption: string;
131 Message: string;
132 List: TStrings );
133Begin
134 DoACLDialog( Caption,
135 Message,
136 List,
137 false, // show cancel
138 mitInfo,
139 false, // show help
140 false, // use yes no
141 nil
142 );
143End;
144
145Procedure DoMessageListHelpDlg( Caption: string;
146 Message: string;
147 List: TStrings;
148 ListHelpCallback: TListHelpCallback );
149Begin
150 DoACLDialog( Caption,
151 Message,
152 List,
153 false, // show cancel
154 mitInfo,
155 true, // show help
156 false, // use yes no
157 ListHelpCallBack
158 );
159End;
160
161Function DoConfirmListDlg( Caption: string;
162 Message: string;
163 List: TStrings ): boolean;
164Begin
165 Result :=
166 DoACLDialog( Caption,
167 Message,
168 List,
169 true, // show cancel
170 mitQuestion,
171 false, // show help
172 false, // use yes no
173 nil // no help callback
174 ) = mrOK;
175End;
176
177Function DoConfirmDlg( Caption: string;
178 Message: string ): boolean;
179Begin
180 Result :=
181 DoACLDialog( Caption,
182 Message,
183 nil, // no list
184 true, // show cancel
185 mitQuestion,
186 false, // show help
187 false, // use yes no
188 nil // no help callback
189 ) = mrOK;
190End;
191
192Procedure DoLongMessageDlg( Caption: String;
193 Message: PChar );
194Var
195 TheDialog: TMessageForm;
196Begin
197 TheDialog := TMessageForm.Create( nil );
198 TheDialog.Caption := Caption;
199 TheDialog.TheText := Message;
200
201 TheDialog.ShowList := false;
202 TheDialog.ShowCancel := false;
203 TheDialog.IconType := mitInfo;
204 TheDialog.ShowHelp := false;
205 TheDialog.UseYesNo := false;
206
207 TheDialog.ShowModal;
208 TheDialog.Destroy;
209End;
210
211Procedure DoMessageDlg( Caption: String;
212 Message: string );
213Begin
214 DoACLDialog( Caption,
215 Message,
216 nil, // no list
217 false, // show cancel
218 mitInfo,
219 false, // show help
220 false, // use yes no
221 nil // no help callback
222 );
223End;
224
225Procedure DoErrorListDlg( Caption: string;
226 Message: string;
227 List: TStrings );
228Begin
229 DoACLDialog( Caption,
230 Message,
231 List,
232 false, // show cancel
233 mitError,
234 false, // show help
235 false, // use yes no
236 nil // no help callback
237 );
238End;
239
240Procedure DoErrorDlg( Caption: String;
241 Message: string );
242Begin
243 DoACLDialog( Caption,
244 Message,
245 nil, // no list
246 false, // show cancel
247 mitError,
248 false, // show help
249 false, // use yes no
250 nil // no help callback
251 );
252End;
253
254Procedure DoWarningDlg( Caption: String;
255 Message: string );
256begin
257 DoACLDialog( Caption,
258 Message,
259 nil, // no list
260 false, // show cancel
261 mitWarning,
262 false, // show help
263 false, // use yes no
264 nil // no help callback
265 );
266end;
267
268Function DoYesNoListDlg( Caption: string;
269 Message: string;
270 List: TStrings ): boolean;
271Begin
272 Result :=
273 DoACLDialog( Caption,
274 Message,
275 List,
276 true, // show "cancel" (=no)
277 mitQuestion,
278 false, // show help
279 true, // use yes no
280 nil // no help callback
281 ) = mrYes;
282End;
283
284Function DoYesNoDlg( Caption: string;
285 Message: string ): boolean;
286Begin
287 Result :=
288 DoACLDialog( Caption,
289 Message,
290 nil, // no list
291 true, // show "cancel" (=no)
292 mitQuestion,
293 false, // show help
294 true, // use yes no
295 nil // no help callback
296 ) = mrYes;
297End;
298
299{$ifdef os2}
300
301var
302 OKButtonCaption: string;
303 CancelButtonCaption: string;
304
305Procedure OnLanguageEvent( Language: TLanguageFile;
306 const Apply: boolean );
307begin
308 if Language <> nil then
309 Language.Prefix := 'TextInputForm.';
310
311 LoadString( Language, Apply, OKButtonCaption, 'OKButtonCaption', '~OK' );
312 LoadString( Language, Apply, CancelButtonCaption, 'CancelButtonCaption', '~Cancel' );
313end;
314
315type
316 TACLQueryDialog = class( TDialog )
317 FEdit: TEdit;
318 FMessageLabel: TLabel;
319 FOKButton: TButton;
320 FCancelButton: TButton;
321 procedure SetupComponent; override;
322 procedure SetupShow; override;
323 end;
324
325procedure TACLQueryDialog.SetupComponent;
326begin
327 inherited SetupComponent;
328
329 Name := 'TextInputForm';
330
331 ClientWidth := 340;
332 ClientHeight := 120;
333
334 FMessageLabel := InsertLabel( self, 10, 90, 320, 20, '' );
335
336 FEdit := TEdit.Create( self );
337 FEdit.SetWindowPos( 10, 60, 320, 20 );
338 FEdit.parent := self;
339 FEdit.TabOrder := 0;
340 FEdit.AutoSize := true;
341
342 FOKButton := InsertButton( self, 10, 10, 90, 30, OKButtonCaption, '' );
343 FOKButton.Name := 'OKButton';
344 FOKButton.ModalResult := mrOK;
345 FOKButton.Default := true;
346 FOKButton.TabOrder := 1;
347
348 FCancelButton := InsertButton( self, 120, 10, 90, 30, CancelButtonCaption, '' );
349 FCancelButton.Name := 'CancelButon';
350 FCancelButton.ModalResult := mrCancel;
351 FCancelButton.Cancel := true;
352 FCancelButton.TabOrder := 2;
353
354end;
355
356procedure TACLQueryDialog.SetupShow;
357begin
358 ScaleForm( self, 11, 16 );
359 FOKButton.Default := true;
360 FEdit.Focus;
361end;
362
363Var
364 QueryDlg: TACLQueryDialog;
365
366// This is a copy of InputQuery from SPCC with the following changes:
367// - slight layout mods
368// - normal buttons instead of bitmap buttons
369// - buttons are centered like my other popup dialogs
370Function DoInputQuery( Const ACaption: String;
371 Const APrompt: String;
372 Var Value: String ): Boolean;
373Begin
374 if QueryDlg = nil then
375 QueryDlg := TACLQueryDialog.Create( Screen.ActiveForm );
376
377 QueryDlg.Caption := ACaption;
378 QueryDlg.FMessageLabel.Caption := APrompt;
379 QueryDlg.FEdit.Text := Value;
380
381 QueryDlg.Execute;
382 Case QueryDlg.ModalResult Of
383 cmOk:
384 Begin
385 Value := QueryDlg.FEdit.Text;
386 Result := True;
387 End;
388
389 Else
390 Begin
391 Result := False;
392 End;
393 End; {Case}
394
395End;
396
397{$endif}
398
399{$ifdef os2}
400Initialization
401 RegisterProcForLanguages( OnLanguageEvent );
402
403 // load our defaults in case the app using us doesn't know about languages
404 OnLanguageEvent( nil, true );
405
406Finalization
407
408// I think application .Destroy will do this.
409// if QueryDlg <> nil then
410// QueryDlg.Destroy;
411
412{$endif}
413
414End.
Note: See TracBrowser for help on using the repository browser.