1{ 2 ***************************************************************************** 3 * * 4 * This file is part of the Lazarus Component Library (LCL) * 5 * * 6 * See the file COPYING.LCL, included in this distribution, * 7 * for details about the copyright. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 12 * * 13 ***************************************************************************** 14 15 LCL Test 3_1 16 17 ComboBox: 18 OnSelect - called when user click on an item on the popup menu. 19 Not called when ItemIndex is set. 20 OnChange - called when user changes text. 21 Not called when ItemIndex is set. 22 Not called when user clicks on an item on the popup menu. 23} 24program Test3_1comboboxselect; 25 26{$mode objfpc}{$H+} 27 28uses 29 Interfaces, FPCAdds, LCLProc, LCLType, Classes, Controls, Forms, TypInfo, 30 LMessages, StdCtrls, Buttons; 31 32type 33 34 { TForm1 } 35 36 TForm1 = class(TForm) 37 procedure Button1Click(Sender: TObject); 38 procedure ComboBox1Change(Sender: TObject); 39 procedure ComboBox1Click(Sender: TObject); 40 procedure ComboBox1CloseUp(Sender: TObject); 41 procedure ComboBox1DropDown(Sender: TObject); 42 procedure ComboBox1EditingDone(Sender: TObject); 43 procedure ComboBox1Select(Sender: TObject); 44 public 45 ComboBox1: TComboBox; 46 Button1: TButton; 47 constructor Create(TheOwner: TComponent); override; 48 end; 49 50{ TForm1 } 51 52procedure TForm1.Button1Click(Sender: TObject); 53var 54 NewItemIndex: Integer; 55begin 56 DebugLn(['TForm1.Button1Click START ComboBox1.ItemIndex=',ComboBox1.ItemIndex]); 57 NewItemIndex:=ComboBox1.ItemIndex+1; 58 if NewItemIndex>=ComboBox1.Items.Count then 59 NewItemIndex:=0; 60 ComboBox1.ItemIndex:=NewItemIndex; 61 DebugLn(['TForm1.Button1Click END ComboBox1.ItemIndex=',ComboBox1.ItemIndex]); 62end; 63 64procedure TForm1.ComboBox1Change(Sender: TObject); 65begin 66 DebugLn(['TForm1.ComboBox1Change ItemIndex=',ComboBox1.ItemIndex]); 67end; 68 69procedure TForm1.ComboBox1Click(Sender: TObject); 70begin 71 DebugLn(['TForm1.ComboBox1Click ItemIndex=',ComboBox1.ItemIndex]); 72end; 73 74procedure TForm1.ComboBox1CloseUp(Sender: TObject); 75begin 76 DebugLn(['TForm1.ComboBox1CloseUp ItemIndex=',ComboBox1.ItemIndex]); 77end; 78 79procedure TForm1.ComboBox1DropDown(Sender: TObject); 80begin 81 DebugLn(['TForm1.ComboBox1DropDown ItemIndex=',ComboBox1.ItemIndex]); 82end; 83 84procedure TForm1.ComboBox1EditingDone(Sender: TObject); 85begin 86 DebugLn(['TForm1.ComboBox1EditingDone ItemIndex=',ComboBox1.ItemIndex]); 87end; 88 89procedure TForm1.ComboBox1Select(Sender: TObject); 90begin 91 DebugLn(['TForm1.ComboBox1Select ItemIndex=',ComboBox1.ItemIndex]); 92end; 93 94constructor TForm1.Create(TheOwner: TComponent); 95begin 96 inherited Create(TheOwner); 97 98 Name:='Form1'; 99 Caption:='Title Form1'; 100 SetBounds(100,90,350,200); 101 102 ComboBox1:=TComboBox.Create(Self); 103 with ComboBox1 do begin 104 Name:='ComboBox1'; 105 SetBounds(10,10,Width,Height); 106 Parent:=Self; 107 OnChange:=@ComboBox1Change; 108 OnClick:=@ComboBox1Click; 109 OnSelect:=@ComboBox1Select; 110 OnCloseUp:=@ComboBox1CloseUp; 111 OnDropDown:=@ComboBox1DropDown; 112 OnEditingDone:=@ComboBox1EditingDone; 113 Items.Add('First'); 114 Items.Add('Second'); 115 Items.Add('Third'); 116 end; 117 118 Button1:=TButton.Create(Self); 119 with Button1 do begin 120 Name:='Button1'; 121 SetBounds(10,40,200,Height); 122 Caption:='Change ItemIndex'; 123 Parent:=Self; 124 OnClick:=@Button1Click; 125 end; 126end; 127 128var 129 Form1: TForm1 = nil; 130begin 131 Application.Title:='test1_1simpleform1'; 132 Application.Initialize; 133 Application.CreateForm(TForm1,Form1); 134 debugln('Form1.Bounds=',dbgs(Form1.BoundsRect)); 135 Application.Run; 136end. 137 138