summaryrefslogtreecommitdiff
path: root/examples/gui/combobox/frm_main.pas
blob: 2b834b51ecdd8887be19255e843ff1a58b6a3ed6 (plain)
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
unit frm_main;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, Classes, gfxbase, fpgfx, gui_edit, 
  gfx_widget, gui_form, gui_label, gui_button,
  gui_listbox, gui_memo, gui_combobox, gui_basegrid, gui_grid, 
  gui_dialogs, gui_checkbox, gui_tree, gui_trackbar, 
  gui_progressbar, gui_radiobutton, gui_tab, gui_menu,
  gui_panel, gui_popupcalendar, gui_gauge, gui_editcombo;

type

  TMainForm = class(TfpgForm)
  private
    procedure cbAutoCompleteChanged(Sender: TObject);
    procedure cbAutoDropDownChanged(Sender: TObject);
    procedure cbAllowNewChanged(Sender: TObject);
    procedure btnAdd1Clicked(Sender: TObject);
    procedure btnFocusClicked(Sender: TObject);
    procedure btnClearClicked(Sender: TObject);
    procedure btnAdd10Clicked(Sender: TObject);
  public
    {@VFD_HEAD_BEGIN: MainForm}
    btnAdd10: TfpgButton;
    btnClear: TfpgButton;
    btnFocus: TfpgButton;
    btnAdd1: TfpgButton;
    cbAutoComplete: TfpgCheckBox;
    Combo1: TfpgComboBox;
    lblName1: TfpgLabel;
    lblName2: TfpgLabel;
    EditCombo1: TfpgEditCombo;
    cbAutoDropdown: TfpgCheckBox;
    lblName3: TfpgLabel;
    lblName4: TfpgLabel;
    cbAllowNew: TfpgComboBox;
    {@VFD_HEAD_END: MainForm}
    procedure AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

implementation

{@VFD_NEWFORM_IMPL}

procedure TMainForm.cbAutoCompleteChanged(Sender: TObject);
begin
  EditCombo1.AutoCompletion := cbAutoComplete.Checked;
end;

procedure TMainForm.cbAutoDropDownChanged(Sender: TObject);
begin
  EditCombo1.AutoDropDown := cbAutoDropdown.Checked;
end;

procedure TMainForm.cbAllowNewChanged(Sender: TObject);
begin
  if cbAllowNew.Text = 'anNo' then
    EditCombo1.AllowNew := anNo
  else if cbAllowNew.Text = 'anYes' then
    EditCombo1.AllowNew := anYes
  else if cbAllowNew.Text = 'anAsk' then
    EditCombo1.AllowNew := anAsk
end;

procedure TMainForm.btnAdd1Clicked(Sender: TObject);
begin
  Combo1.Items.Add(Format('Item %2d', [Combo1.Items.Count]));
  EditCombo1.Items.Add(Format('Item %2d', [EditCombo1.Items.Count]));
end;

procedure TMainForm.btnFocusClicked(Sender: TObject);
begin
  if Combo1.Items.Count > 1 then
    Combo1.FocusItem := 2;
  if EditCombo1.Items.Count > 1 then
    EditCombo1.FocusItem := 2;
end;

procedure TMainForm.btnClearClicked(Sender: TObject);
begin
  Combo1.Items.Clear;
  EditCombo1.Items.Clear;
end;

procedure TMainForm.btnAdd10Clicked(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 10 do
  begin
    Combo1.Items.Add(Format('Item %2d', [Combo1.Items.Count]));
    EditCombo1.Items.Add(Format('Item %2d', [EditCombo1.Items.Count]));
  end;
end;

procedure TMainForm.AfterCreate;
begin
  {@VFD_BODY_BEGIN: MainForm}
  Name := 'MainForm';
  SetPosition(345, 220, 344, 260);
  WindowTitle := 'ComboBox test';
  WindowPosition := wpScreenCenter;

  btnAdd10 := TfpgButton.Create(self);
  with btnAdd10 do
  begin
    Name := 'btnAdd10';
    SetPosition(220, 28, 92, 23);
    Text := 'Add 10 items';
    FontDesc := '#Label1';
    ImageName := '';
    TabOrder := 1;
    OnClick := @btnAdd10Clicked;
  end;

  btnClear := TfpgButton.Create(self);
  with btnClear do
  begin
    Name := 'btnClear';
    SetPosition(220, 56, 92, 23);
    Text := 'Clear Items';
    FontDesc := '#Label1';
    ImageName := '';
    TabOrder := 2;
    OnClick := @btnClearClicked;
  end;

  btnFocus := TfpgButton.Create(self);
  with btnFocus do
  begin
    Name := 'btnFocus';
    SetPosition(220, 84, 92, 23);
    Text := 'FocusItem = 2';
    FontDesc := '#Label1';
    ImageName := '';
    TabOrder := 3;
    OnClick := @btnFocusClicked;
  end;

  btnAdd1 := TfpgButton.Create(self);
  with btnAdd1 do
  begin
    Name := 'btnAdd1';
    SetPosition(220, 112, 92, 23);
    Text := 'Add 1 item';
    FontDesc := '#Label1';
    ImageName := '';
    TabOrder := 4;
    OnClick := @btnAdd1Clicked;
  end;

  cbAutoComplete := TfpgCheckBox.Create(self);
  with cbAutoComplete do
  begin
    Name := 'cbAutoComplete';
    SetPosition(216, 168, 120, 19);
    FontDesc := '#Label1';
    TabOrder := 6;
    Text := 'Auto Complete';
    OnChange := @cbAutoCompleteChanged;
  end;

  Combo1 := TfpgComboBox.Create(self);
  with Combo1 do
  begin
    Name := 'Combo1';
    SetPosition(8, 24, 168, 21);
    FontDesc := '#List';
    TabOrder := 6;
  end;

  lblName1 := TfpgLabel.Create(self);
  with lblName1 do
  begin
    Name := 'lblName1';
    SetPosition(8, 8, 176, 15);
    FontDesc := '#Label1';
    Text := 'Static ComboBox';
  end;

  lblName2 := TfpgLabel.Create(self);
  with lblName2 do
  begin
    Name := 'lblName2';
    SetPosition(8, 68, 176, 15);
    FontDesc := '#Label1';
    Text := 'Edit ComboBox';
  end;

  EditCombo1 := TfpgEditCombo.Create(self);
  with EditCombo1 do
  begin
    Name := 'EditCombo1';
    SetPosition(8, 88, 168, 21);
  end;

  cbAutoDropdown := TfpgCheckBox.Create(self);
  with cbAutoDropdown do
  begin
    Name := 'cbAutoDropdown';
    SetPosition(216, 188, 120, 19);
    FontDesc := '#Label1';
    TabOrder := 9;
    Text := 'Auto Dropdown';
    OnChange := @cbAutoDropDownChanged;
  end;

  lblName3 := TfpgLabel.Create(self);
  with lblName3 do
  begin
    Name := 'lblName3';
    SetPosition(204, 148, 128, 15);
    FontDesc := '#Label2';
    Text := 'EditCombo only';
  end;

  lblName4 := TfpgLabel.Create(self);
  with lblName4 do
  begin
    Name := 'lblName4';
    SetPosition(204, 8, 136, 15);
    FontDesc := '#Label2';
    Text := 'Both components';
  end;

  cbAllowNew := TfpgComboBox.Create(self);
  with cbAllowNew do
  begin
    Name := 'cbAllowNew';
    SetPosition(220, 212, 100, 21);
    FontDesc := '#List';
    Items.Add('anNo');
    Items.Add('anYes');
    Items.Add('anAsk');
    TabOrder := 13;
    OnChange := @cbAllowNewChanged;
    FocusItem := 0;
  end;

  {@VFD_BODY_END: MainForm}

end;


end.