From 5bd27bfb26b56fca17c0be51350f4197dca3d6cc Mon Sep 17 00:00:00 2001 From: blikblum Date: Thu, 21 Apr 2011 15:35:38 +0000 Subject: [PATCH] lcl: in TDBLookupListBox update record when selection is changed (Delphi compatible) git-svn-id: trunk@30414 - --- lcl/dbctrls.pp | 7 ++++--- lcl/include/customdblistbox.inc | 24 ------------------------ lcl/include/dblistbox.inc | 26 ++++++++++++++++++++++++++ lcl/include/dblookuplistbox.inc | 23 +++++++++++++++++++++++ 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index d59727468a..072b9429d8 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -373,9 +373,6 @@ Type public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure Click; override; - procedure EditingDone; override; - property Field: TField read GetField; property DataField: string read GetDataField write SetDataField; property DataSource: TDataSource read GetDataSource write SetDataSource; @@ -389,7 +386,10 @@ Type TDBListBox = class(TCustomDBListBox) protected procedure DataChange(Sender: TObject); override; + procedure DoSelectionChange(User: Boolean); override; procedure UpdateData(Sender: TObject); override; + public + procedure EditingDone; override; published property Align; property Anchors; @@ -454,6 +454,7 @@ Type procedure SetNullValueKey(const AValue: TShortCut); protected procedure DataChange(Sender: TObject); override; + procedure DoSelectionChange(User: Boolean); override; procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure InitializeWnd; override; procedure UpdateData(Sender: TObject); override; diff --git a/lcl/include/customdblistbox.inc b/lcl/include/customdblistbox.inc index 07924e72e1..07835348fe 100644 --- a/lcl/include/customdblistbox.inc +++ b/lcl/include/customdblistbox.inc @@ -135,30 +135,6 @@ begin end; end; -procedure TCustomDBListBox.Click; -begin - //make sure we are in modify mode if can edit - //so if a user changed the selection it can be - //updated, and if not cancel out ala ReadOnly - if not FDataLink.Edit then - begin - // restore value - DataChange(self); - Exit; - end; - inherited Click; - FDataLink.Modified; -end; - -procedure TCustomDBListBox.EditingDone; -begin - //update record only when loosing focus to keep the ability to cancel - //after changing the selection more than one time - if not Focused then - FDataLink.UpdateRecord; - inherited EditingDone; -end; - { Public Methods } constructor TCustomDBListBox.Create(AOwner: TComponent); begin diff --git a/lcl/include/dblistbox.inc b/lcl/include/dblistbox.inc index 93ad348f3a..edd619ac55 100644 --- a/lcl/include/dblistbox.inc +++ b/lcl/include/dblistbox.inc @@ -36,9 +36,35 @@ begin ItemIndex := -1; end; +procedure TDBListBox.DoSelectionChange(User: Boolean); +begin + if User then + begin + //make sure we are in modify mode if can edit + //so if a user changed the selection it can be + //updated, and if not cancel out ala ReadOnly + if FDataLink.Edit then + FDataLink.Modified + else + begin + // restore value + DataChange(Self); + //necessary to avoid double call of SelectionChange + Exit; + end; + end; + inherited DoSelectionChange(User); +end; + procedure TDBListBox.UpdateData(Sender: TObject); begin if ItemIndex >= 0 then FDataLink.Field.Text := Items[ItemIndex]; end; +procedure TDBListBox.EditingDone; +begin + FDataLink.UpdateRecord; + inherited EditingDone; +end; + diff --git a/lcl/include/dblookuplistbox.inc b/lcl/include/dblookuplistbox.inc index 10bf18f4ab..23d2fd5114 100644 --- a/lcl/include/dblookuplistbox.inc +++ b/lcl/include/dblookuplistbox.inc @@ -58,6 +58,29 @@ begin end; end; +procedure TDBLookupListBox.DoSelectionChange(User: Boolean); +begin + if User then + begin + //make sure we are in modify mode if can edit + //so if a user changed the selection it can be + //updated, and if not cancel out ala ReadOnly + if FDataLink.Edit then + begin + FDataLink.Modified; + FDataLink.UpdateRecord; + end + else + begin + // restore value + DataChange(Self); + //necessary to avoid double call of SelectionChange + Exit; + end; + end; + inherited DoSelectionChange(User); +end; + procedure TDBLookupListBox.KeyDown(var Key: Word; Shift: TShiftState); begin if FLookup.HandleNullKey(Key, Shift) then