From 437c6649fb149475ee90c0f8efb86f51dc20d630 Mon Sep 17 00:00:00 2001 From: blikblum Date: Sat, 28 Apr 2012 12:39:08 +0000 Subject: [PATCH] lcl: prevent loop in TDBLookup.Initialize after changing ListLink.Datasource git-svn-id: trunk@37057 - --- lcl/dbctrls.pp | 1 + lcl/include/dblookup.inc | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index 1436c600b7..65a7307faa 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -134,6 +134,7 @@ Type FLookUpFieldIsCached: Boolean; FLookupCache: boolean; procedure ActiveChange(Sender: TObject); + procedure ChangeListLinkDataSource(NewDataSource: TDataSource); procedure EditingChange(Sender: TObject); procedure FetchLookupData; function GetKeyFieldName: string; diff --git a/lcl/include/dblookup.inc b/lcl/include/dblookup.inc index fb652c0882..8e8cd3b43f 100644 --- a/lcl/include/dblookup.inc +++ b/lcl/include/dblookup.inc @@ -88,6 +88,16 @@ begin Initialize(FControlLink, FControlItems); end; +procedure TDBLookup.ChangeListLinkDataSource(NewDataSource: TDataSource); +begin + if NewDataSource <> FListLink.DataSource then + begin + FListLink.OnActiveChange := nil; + FListLink.DataSource := NewDataSource; + FListLink.OnActiveChange := @ActiveChange; + end; +end; + procedure TDBLookup.EditingChange(Sender: TObject); begin if FListLink.Active and not (FListLink.Editing) then @@ -252,21 +262,16 @@ begin FLookupSource := TDataSource.Create(Self); if (FLookupSource.DataSet <> FControlLink.Field.LookupDataSet) then FLookupSource.DataSet:= FControlLink.Field.LookupDataSet; - if FListLink.DataSource <> FLookupSource then - FListLink.DataSource := FLookupSource; + ChangeListLinkDataSource(FLookupSource); FDataFieldNames := FControlLink.Field.KeyFields; FKeyFieldNames := FControlLink.Field.LookupKeyFields; end else FDataFieldNames := FControlLink.Field.FieldName; - FDataFields.Clear; FControlLink.DataSet.GetFieldList(FDataFields, FDataFieldNames); end; end; if not FHasLookUpField then - begin - if FListLink.DataSource <> FListSource then - FListLink.DataSource := FListSource; - end; + ChangeListLinkDataSource(FListSource); if (FKeyFieldNames > '') and Assigned(FListLink.Dataset) then begin @@ -282,7 +287,6 @@ begin try if FListLink.DataSet.Active then begin - FKeyFields.Clear; FListLink.DataSet.GetFieldList(ListFields, FListFieldName); FListLink.DataSet.GetFieldList(FKeyFields, FKeyFieldNames); if FHasLookUpField then