-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.pas
188 lines (176 loc) · 5.19 KB
/
dialog.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
unit dialog;
{$mode objfpc}{$H+}
interface
uses
SysUtils, LCLIntf, LCLType, Classes, Graphics, Controls,
Forms, Dialogs, Menus, StdCtrls, ExtCtrls, Types;
function InputCombo(const ACaption, APrompt: string; const AList: TStrings): string;
function CheckListDialog(const ACaption, APrompt: string; const AList: TStrings;
Checked: boolean = False): string;
implementation
uses CheckLst;
resourcestring
strOK = 'OK';
strCancel = 'Cancelar';
function GetCharSize(Canvas: TCanvas): TPoint;
var
I: integer;
Buffer: array[0..51] of char;
begin
for I := 0 to 25 do
Buffer[I] := Chr(I + Ord('A'));
for I := 0 to 25 do
Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;
function GetSelectedItems(CheckListBox: TCheckListBox): string;
var
i: integer;
begin
Result := '';
for i := 0 to CheckListBox.Items.Count - 1 do
if CheckListBox.State[i] = cbChecked then
Result := Result + QuotedStr(CheckListBox.Items[i]) + ',';
Result := Copy(Result, 0, Length(Result) - 1);
end;
function InputCombo(const ACaption, APrompt: string; const AList: TStrings): string;
var
Form: TForm;
Prompt: TLabel;
Combo: TComboBox;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: integer;
begin
Result := '';
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := Font;
DialogUnits := GetCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;
ClientWidth := MulDiv(180, DialogUnits.X, 4);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
Caption := APrompt;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
WordWrap := True;
end;
Combo := TComboBox.Create(Form);
with Combo do
begin
Parent := Form;
Style := csDropDownList;
Items.Assign(AList);
ItemIndex := 0;
Left := Prompt.Left;
Top := Prompt.Top + Prompt.Height + 5;
Width := MulDiv(164, DialogUnits.X, 4);
end;
ButtonTop := Combo.Top + Combo.Height + 15;
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
Caption := strOK; //'OK';
ModalResult := mrOk;
default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := strCancel; //'Cancelar';
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), Combo.Top + Combo.Height + 15,
ButtonWidth, ButtonHeight);
Form.ClientHeight := Top + Height + 13;
end;
if ShowModal = mrOk then
Result := Combo.Text;
finally
Form.Free;
end;
end;
function CheckListDialog(const ACaption, APrompt: string; const AList: TStrings;
Checked: boolean = False): string;
var
Form: TForm;
Prompt: TLabel;
ListBox: TCheckListBox;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight, I: integer;
begin
Result := '';
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := Font;
DialogUnits := GetCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;
ClientWidth := MulDiv(180, DialogUnits.X, 4);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
Caption := APrompt;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
WordWrap := True;
end;
ListBox := TCheckListBox.Create(Form);
with ListBox do
begin
Parent := Form;
Items.Assign(AList);
ItemIndex := 0;
Left := Prompt.Left;
Top := Prompt.Top + Prompt.Height + 5;
Width := MulDiv(164, DialogUnits.X, 4);
end;
for I := 0 to ListBox.Count - 1 do
if Checked then
ListBox.Checked[I] := True
else
ListBox.Checked[I] := False;
ButtonTop := ListBox.Top + ListBox.Height + 15;
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
Caption := strOK; //'OK';
ModalResult := mrOk;
default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := strCancel; //'Cancelar';
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), ListBox.Top + ListBox.Height + 15,
ButtonWidth, ButtonHeight);
Form.ClientHeight := Top + Height + 13;
end;
if ShowModal = mrOk then
Result := GetSelectedItems(ListBox);
finally
Form.Free;
end;
end;
end.