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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
|
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
TIntArray = array of Longint;
type
{ TForm1 }
TForm1 = class(TForm)
ButtonAskUser: TButton;
ButtonPromptUser: TButton;
ButtonAppMsgbox: TButton;
ButtonLCLIntfMsgbox: TButton;
ButtonMsgDlg: TButton;
CheckFlag_AbortRetryIgnore: TRadioButton;
CheckFlag_Ok: TRadioButton;
CheckFlag_OkCancel: TRadioButton;
CheckFlag_RetryCancel: TRadioButton;
CheckFlag_YesNo: TRadioButton;
CheckFlag_YesNoCancel: TRadioButton;
EditCaption: TEdit;
EditMessage: TEdit;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Label1: TLabel;
Label2: TLabel;
ButtonClose: TButton;
CheckFlag_Info: TRadioButton;
CheckFlag_Warn: TRadioButton;
CheckFlag_Error: TRadioButton;
CheckFlag_Ask: TRadioButton;
CheckFlag_NoneIcon: TRadioButton;
CheckFlag_B1: TRadioButton;
CheckFlag_B2: TRadioButton;
CheckFlag_B3: TRadioButton;
CheckFlag_B4: TRadioButton;
procedure ButtonAppMsgboxClick(Sender: TObject);
procedure ButtonAskUserClick(Sender: TObject);
procedure ButtonCloseClick(Sender: TObject);
procedure ButtonLCLIntfMsgboxClick(Sender: TObject);
procedure ButtonMsgDlgClick(Sender: TObject);
procedure ButtonPromptUserClick(Sender: TObject);
private
function GetMsgFlags: integer;
function GetDlgType: TMsgDlgType;
function GetDlgButtons: TMsgDlgButtons;
function GetDlgTypeInt: integer;
function GetBtnArray: TIntArray;
function ButtonIdToString(N: integer): string;
function ButtonAltIdToString(N: integer): string;
public
end;
var
Form1: TForm1;
implementation
uses
LCLType, LCLProc, LCLIntf, InterfaceBase, System.UITypes;
{$R *.lfm}
{ TForm1 }
procedure TForm1.ButtonCloseClick(Sender: TObject);
begin
Close;
end;
function TForm1.GetMsgFlags: integer;
begin
Result:= 0;
if CheckFlag_Ok.Checked then
Result:= MB_OK
else
if CheckFlag_OkCancel.Checked then
Result:= MB_OKCANCEL
else
if CheckFlag_YesNo.Checked then
Result:= MB_YESNO
else
if CheckFlag_YesNoCancel.Checked then
Result:= MB_YESNOCANCEL
else
if CheckFlag_RetryCancel.Checked then
Result:= MB_RETRYCANCEL
else
if CheckFlag_AbortRetryIgnore.Checked then
Result:= MB_ABORTRETRYIGNORE;
if CheckFlag_Info.Checked then
Inc(Result, MB_ICONINFORMATION)
else
if CheckFlag_Warn.Checked then
Inc(Result, MB_ICONWARNING)
else
if CheckFlag_Error.Checked then
Inc(Result, MB_ICONERROR)
else
if CheckFlag_Ask.Checked then
Inc(Result, MB_ICONQUESTION);
if CheckFlag_B1.Checked then
Inc(Result, MB_DEFBUTTON1)
else
if CheckFlag_B2.Checked then
Inc(Result, MB_DEFBUTTON2)
else
if CheckFlag_B3.Checked then
Inc(Result, MB_DEFBUTTON3)
else
if CheckFlag_B4.Checked then
Inc(Result, MB_DEFBUTTON4);
end;
function TForm1.GetDlgType: TMsgDlgType;
begin
if CheckFlag_Info.Checked then
Result:= mtInformation
else
if CheckFlag_Warn.Checked then
Result:= mtWarning
else
if CheckFlag_Error.Checked then
Result:= mtError
else
if CheckFlag_Ask.Checked then
Result:= mtConfirmation
else
Result:= mtCustom;
end;
function TForm1.GetDlgButtons: TMsgDlgButtons;
begin
if CheckFlag_Ok.Checked then
Result:= [mbOk]
else
if CheckFlag_OkCancel.Checked then
Result:= mbOKCancel
else
if CheckFlag_YesNo.Checked then
Result:= mbYesNo
else
if CheckFlag_YesNoCancel.Checked then
Result:= mbYesNoCancel
else
if CheckFlag_RetryCancel.Checked then
Result:= [mbRetry, mbCancel]
else
if CheckFlag_AbortRetryIgnore.Checked then
Result:= mbAbortRetryIgnore
else
Result:= [mbOk];
end;
function TForm1.GetDlgTypeInt: integer;
begin
if CheckFlag_Info.Checked then
Result:= idDialogInfo
else
if CheckFlag_Warn.Checked then
Result:= idDialogWarning
else
if CheckFlag_Error.Checked then
Result:= idDialogError
else
if CheckFlag_Ask.Checked then
Result:= idDialogConfirm
else
Result:= 0;
end;
function TForm1.GetBtnArray: TIntArray;
begin
SetLength(Result, 0);
if CheckFlag_Ok.Checked then
begin
SetLength(Result, 1);
Result[0]:= idButtonOk;
end
else
if CheckFlag_OkCancel.Checked then
begin
SetLength(Result, 2);
Result[0]:= idButtonOk;
Result[1]:= idButtonCancel;
end
else
if CheckFlag_YesNo.Checked then
begin
SetLength(Result, 2);
Result[0]:= idButtonYes;
Result[1]:= idButtonNo;
end
else
if CheckFlag_YesNoCancel.Checked then
begin
SetLength(Result, 3);
Result[0]:= idButtonYes;
Result[1]:= idButtonNo;
Result[2]:= idButtonCancel;
end
else
if CheckFlag_RetryCancel.Checked then
begin
SetLength(Result, 2);
Result[0]:= idButtonRetry;
Result[1]:= idButtonCancel;
end
else
if CheckFlag_AbortRetryIgnore.Checked then
begin
SetLength(Result, 3);
Result[0]:= idButtonAbort;
Result[1]:= idButtonRetry;
Result[2]:= idButtonIgnore;
end;
end;
function TForm1.ButtonIdToString(N: integer): string;
begin
case N of
ID_OK: Result:= 'ID_OK';
ID_CANCEL: Result:= 'ID_CANCEL';
ID_YES: Result:= 'ID_YES';
ID_NO: Result:= 'ID_NO';
ID_RETRY: Result:= 'ID_RETRY';
ID_IGNORE: Result:= 'ID_IGNORE';
ID_ABORT: Result:= 'ID_ABORT';
ID_CLOSE: Result:= 'ID_CLOSE';
ID_HELP: Result:= 'ID_HELP';
else Result:= IntToStr(N);
end;
end;
function TForm1.ButtonAltIdToString(N: integer): string;
begin
case N of
idButtonOk: Result:= 'idButtonOk';
idButtonCancel: Result:= 'idButtonCancel';
idButtonYes: Result:= 'idButtonYes';
idButtonNo: Result:= 'idButtonNo';
idButtonRetry: Result:= 'idButtonRetry';
idButtonIgnore: Result:= 'idButtonIgnore';
idButtonAbort: Result:= 'idButtonAbort';
idButtonClose: Result:= 'idButtonClose';
idButtonHelp: Result:= 'idButtonHelp';
else Result:= IntToStr(N);
end;
end;
procedure TForm1.ButtonAppMsgboxClick(Sender: TObject);
var
N: integer;
begin
N:= Application.MessageBox(
PChar(EditMessage.Text),
PChar(EditCaption.Text),
GetMsgFlags);
Caption:= 'Application.MessageBox() returned '+ButtonIdToString(N);
end;
procedure TForm1.ButtonAskUserClick(Sender: TObject);
var
Buttons: TDialogButtons;
N: integer;
NDef: integer;
begin
NDef:= -1;
if CheckFlag_B1.Checked then
NDef:= 0
else
if CheckFlag_B2.Checked then
NDef:= 1
else
if CheckFlag_B3.Checked then
NDef:= 2
else
if CheckFlag_B4.Checked then
NDef:= 3;
Buttons:= TDialogButtons.Create(TDialogButton);
with Buttons.Add do
begin
Caption:= '<ok>';
ModalResult:= mrOk;
end;
with Buttons.Add do
begin
Caption:= '<cancel>';
ModalResult:= mrCancel;
end;
with Buttons.Add do
begin
Caption:= '<yes>';
ModalResult:= mrYes;
end;
with Buttons.Add do
begin
Caption:= '<no>';
ModalResult:= mrNo;
end;
with Buttons.Add do
begin
Caption:= '<ignore>';
ModalResult:= mrIgnore;
end;
if (NDef>=0) and (NDef<Buttons.Count) then
Buttons.DefaultButton:= Buttons[NDef];
N:= AskUser(
EditCaption.Text,
EditMessage.Text,
GetDlgTypeInt,
Buttons,
0);
FreeAndNil(Buttons);
Caption:= 'AskUser() returned '+ButtonIdToString(N);
end;
procedure TForm1.ButtonLCLIntfMsgboxClick(Sender: TObject);
var
N: integer;
begin
N:= LCLIntf.MessageBox(Handle,
PChar(EditMessage.Text),
PChar(EditCaption.Text),
GetMsgFlags
);
Caption:= 'LCLIntf.MessageBox() returned '+ButtonIdToString(N);
end;
procedure TForm1.ButtonMsgDlgClick(Sender: TObject);
var
Res: TModalResult;
begin
Res:= MessageDlg(
EditCaption.Text,
EditMessage.Text,
GetDlgType,
GetDlgButtons,
0);
Caption:= 'MessageDlg() returned '+ModalResultStr[Res];
end;
procedure TForm1.ButtonPromptUserClick(Sender: TObject);
var
Btn: array of Longint;
N: integer;
begin
Btn:= GetBtnArray;
if Length(Btn)=0 then exit;
N:= PromptUser(
EditCaption.Text,
EditMessage.Text,
GetDlgTypeInt,
@Btn[0],
Length(Btn),
0,
0);
Caption:= 'PromptUser() returned '+ButtonAltIdToString(N);
end;
end.
|