1{%MainUnit ../dbctrls.pp} 2 3{****************************************************************************** 4 TDBListBox 5 data aware ListBox, base found in dbctrls.pp 6 ****************************************************************************** 7 8 ***************************************************************************** 9 This file is part of the Lazarus Component Library (LCL) 10 11 See the file COPYING.modifiedLGPL.txt, included in this distribution, 12 for details about the license. 13 ***************************************************************************** 14} 15 16// included by dbctrls.pp 17 18{ TDBListBox } 19 20{ Protected Methods } 21 22procedure TDBListBox.DataChange(Sender: TObject); 23var 24 DataLinkField: TField; 25begin 26 DataLinkField := FDataLink.Field; 27 if Assigned(DataLinkField) then 28 ItemIndex := Items.IndexOf(DataLinkField.Text) 29 else 30 ItemIndex := -1; 31end; 32 33procedure TDBListBox.DoSelectionChange(User: Boolean); 34begin 35 if User then 36 begin 37 if FDataLink.CanModify then 38 begin 39 //protect against undesired call to DataChange 40 FDataLink.OnDataChange := nil; 41 if FDataLink.Edit then 42 FDataLink.Modified; 43 FDataLink.OnDataChange := @DataChange; 44 end 45 else 46 DataChange(Self); 47 end; 48 inherited DoSelectionChange(User); 49end; 50 51procedure TDBListBox.UpdateData(Sender: TObject); 52begin 53 if ItemIndex >= 0 then 54 FDataLink.Field.Text := Items[ItemIndex]; 55end; 56 57procedure TDBListBox.EditingDone; 58begin 59 FDataLink.UpdateRecord; 60 inherited EditingDone; 61end; 62 63