OnDropDown (Delphi)
Description
This example fills the list of a combo box with the set of open forms when you drop down the list. The list is regenerated every time the list is dropped down, so if the application opens or closes forms, the combo box stays current.
Code
procedure TForm1.ComboBox1DropDown(Sender: TObject);
var
I: Integer;
begin
with ComboBox1 do
begin
Items.BeginUpdate; { Prevent repaints until done. }
Items.Clear; { Empty the list of any old values. }
for I := 0 to Screen.CustomFormCount - 1 do
begin
if (Screen.CustomForms[I].Visible) then
Items.Add(Screen.CustomForms[I].Caption); { Add form name. }
end;
Items.EndUpdate; {Reenable painting. }
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Sorted := True; { Make sure the form names are sorted. }
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form3.Show;
end;
Uses
- Vcl.StdCtrls.TCustomCombo.OnDropDown ( fr | de | ja )
- Vcl.StdCtrls.TCustomComboBox.Sorted ( fr | de | ja )
- System.Classes.TStrings.Clear ( fr | de | ja )
- System.Classes.TStrings.BeginUpdate ( fr | de | ja )
- System.Classes.TStrings.EndUpdate ( fr | de | ja )