-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuDialog.pas
More file actions
98 lines (85 loc) · 2.3 KB
/
Copy pathuDialog.pas
File metadata and controls
98 lines (85 loc) · 2.3 KB
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
unit uDialog;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TfDialog = class(TForm)
lbText: TLabel;
procedure Button1Click(Sender: TObject);
private
modal_res: integer;
{ Private declarations }
procedure CreateButtons(buttons: TStringList);
public
{ Public declarations }
function ShowDialog(msg : string; buttons : integer ): integer; //0 -Ok; 1- Ok,Cancel; 2- Yes,No; 3- Yes,No,Cancel
end;
implementation
{$R *.dfm}
procedure TfDialog.CreateButtons(buttons: TStringList);
var i : integer;
bbtmn : TBitBtn;
wrap: integer;
begin
if buttons = nil then exit;
i := buttons.Count * (75 + 25)+25;
if lbText.Width + 50 >= i then
Self.Width := lbText.Width + 50
else
Self.Width := i;
lbText.Left := Trunc((Self.Width - lbText.Width) /2);
for i:= 0 to buttons.Count-1 do
begin
bbtmn := TBitBtn.Create(Self);
bbtmn.Parent := Self;
bbtmn.Width := 75;
bbtmn.Height := 25;
bbtmn.Top := 75;
bbtmn.Caption := buttons[i];
bbtmn.Tag := integer(buttons.Objects[i]);//???
bbtmn.OnClick := Button1Click;
wrap := Trunc((Self.Width - buttons.Count * bbtmn.Width)/(buttons.Count+1));
bbtmn.Left := (i+1)*wrap + i* 75;
end;
end;
function TfDialog.ShowDialog(msg : string; buttons : integer): integer;
var bbtmn : TBitBtn;
wrap: integer;
btns: TStringList;
begin
lbText.Caption := msg;
btns := TStringList.Create;
case buttons of
0: begin
btns.AddObject('Ok',TObject(mrOk));
CreateButtons(btns);
end;
1: begin
btns.AddObject('Ok',TObject(mrOk));
btns.AddObject('Cancel',TObject(mrCancel));
CreateButtons(btns);
end;
2: begin
btns.AddObject('Yes',TObject(mrYes));
btns.AddObject('No',TObject(mrNo));
CreateButtons(btns);
end;
3: begin
btns.AddObject('Yes',TObject(mrYes));
btns.AddObject('No',TObject(mrNo));
btns.AddObject('Cancel',TObject(mrCancel));
CreateButtons(btns);
end;
end;
btns.Free;
modal_res := 0;
ShowModal;
result := modal_res;
end;
procedure TfDialog.Button1Click(Sender: TObject);
begin
modal_res := TBitBtn(Sender).Tag;
Close;
end;
end.