diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index c0a4563ade..8ac34e50da 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -473,6 +473,7 @@ Type procedure KeyDown(var Key: Word; Shift: TShiftState); override; procedure Loaded; override; procedure UpdateData(Sender: TObject); override; + function IsUnbound: boolean; public constructor Create(AOwner: TComponent); override; property KeyValue: Variant read GetKeyValue write SetKeyValue; diff --git a/lcl/include/dblookuplistbox.inc b/lcl/include/dblookuplistbox.inc index 0cf17b3fb1..f465fab655 100644 --- a/lcl/include/dblookuplistbox.inc +++ b/lcl/include/dblookuplistbox.inc @@ -30,6 +30,11 @@ begin FLookup.UpdateData(ItemIndex, FScrollListDataset); end; +function TDBLookupListBox.IsUnbound: boolean; +begin + Result := (FDataLink.DataSource = nil) or (DataField = ''); +end; + procedure TDBLookupListBox.ActiveChange(Sender: TObject); begin if FDataLink.Active then @@ -54,15 +59,18 @@ end; procedure TDBLookupListBox.DoSelectionChange(User: Boolean); begin if User then - begin - if FDataLink.CanModify then - begin - FDataLink.Modified; - FDataLink.UpdateRecord; - end + if IsUnbound then + UpdateData(Self) else - DataChange(Self); - end; + begin + if FDataLink.CanModify then + begin + FDataLink.Modified; + FDataLink.UpdateRecord; + end + else + DataChange(Self); + end; inherited DoSelectionChange(User); end;