lcl: prevent loop in TDBLookup.Initialize after changing ListLink.Datasource

git-svn-id: trunk@37057 -
This commit is contained in:
blikblum 2012-04-28 12:39:08 +00:00
parent 4b7489f68f
commit 437c6649fb
2 changed files with 13 additions and 8 deletions

View File

@ -134,6 +134,7 @@ Type
FLookUpFieldIsCached: Boolean; FLookUpFieldIsCached: Boolean;
FLookupCache: boolean; FLookupCache: boolean;
procedure ActiveChange(Sender: TObject); procedure ActiveChange(Sender: TObject);
procedure ChangeListLinkDataSource(NewDataSource: TDataSource);
procedure EditingChange(Sender: TObject); procedure EditingChange(Sender: TObject);
procedure FetchLookupData; procedure FetchLookupData;
function GetKeyFieldName: string; function GetKeyFieldName: string;

View File

@ -88,6 +88,16 @@ begin
Initialize(FControlLink, FControlItems); Initialize(FControlLink, FControlItems);
end; 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); procedure TDBLookup.EditingChange(Sender: TObject);
begin begin
if FListLink.Active and not (FListLink.Editing) then if FListLink.Active and not (FListLink.Editing) then
@ -252,21 +262,16 @@ begin
FLookupSource := TDataSource.Create(Self); FLookupSource := TDataSource.Create(Self);
if (FLookupSource.DataSet <> FControlLink.Field.LookupDataSet) then if (FLookupSource.DataSet <> FControlLink.Field.LookupDataSet) then
FLookupSource.DataSet:= FControlLink.Field.LookupDataSet; FLookupSource.DataSet:= FControlLink.Field.LookupDataSet;
if FListLink.DataSource <> FLookupSource then ChangeListLinkDataSource(FLookupSource);
FListLink.DataSource := FLookupSource;
FDataFieldNames := FControlLink.Field.KeyFields; FDataFieldNames := FControlLink.Field.KeyFields;
FKeyFieldNames := FControlLink.Field.LookupKeyFields; FKeyFieldNames := FControlLink.Field.LookupKeyFields;
end else end else
FDataFieldNames := FControlLink.Field.FieldName; FDataFieldNames := FControlLink.Field.FieldName;
FDataFields.Clear;
FControlLink.DataSet.GetFieldList(FDataFields, FDataFieldNames); FControlLink.DataSet.GetFieldList(FDataFields, FDataFieldNames);
end; end;
end; end;
if not FHasLookUpField then if not FHasLookUpField then
begin ChangeListLinkDataSource(FListSource);
if FListLink.DataSource <> FListSource then
FListLink.DataSource := FListSource;
end;
if (FKeyFieldNames > '') and Assigned(FListLink.Dataset) then if (FKeyFieldNames > '') and Assigned(FListLink.Dataset) then
begin begin
@ -282,7 +287,6 @@ begin
try try
if FListLink.DataSet.Active then if FListLink.DataSet.Active then
begin begin
FKeyFields.Clear;
FListLink.DataSet.GetFieldList(ListFields, FListFieldName); FListLink.DataSet.GetFieldList(ListFields, FListFieldName);
FListLink.DataSet.GetFieldList(FKeyFields, FKeyFieldNames); FListLink.DataSet.GetFieldList(FKeyFields, FKeyFieldNames);
if FHasLookUpField then if FHasLookUpField then