From fe582332c2d0b79066435ab9ef1c9e1b86364b1c Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 17 Dec 2015 14:23:04 +0000 Subject: [PATCH] LCL: improve the workaround to support fpc 2.6.4 TMemDataset in a way that other datasets are not affected. Issues #26356, #27959 git-svn-id: branches/fixes_1_6@50864 - --- lcl/dbctrls.pp | 3 ++ lcl/include/dblookup.inc | 59 ++++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index 5790b8cbcc..bfe1c62a9a 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -127,6 +127,9 @@ Type FLookUpFieldIsCached: Boolean; FLookupCache: Boolean; FInitializing: Boolean; + {$IF FPC_FULLVERSION < 30000} + FFetchingLookupData: Boolean; + {$ENDIF} procedure ActiveChange(Sender: TObject); procedure DatasetChange(Sender: TObject); procedure DoInitialize; diff --git a/lcl/include/dblookup.inc b/lcl/include/dblookup.inc index a3c7e35169..1fe43bd99a 100644 --- a/lcl/include/dblookup.inc +++ b/lcl/include/dblookup.inc @@ -76,10 +76,15 @@ begin end; procedure TDBLookupDataLink.DataEvent(Event: TDataEvent; Info: Ptrint); +var + I: Integer; + S: TDataSetState; begin inherited DataEvent(Event, Info); if Event = deDataSetChange then begin + I := DataSet.RecordCount; + S := DataSet.State; if FRecordUpdated or ((FLookup.ControlItems <> nil) and (FLookup.ControlItems.Count <> DataSet.RecordCount)) then begin FRecordUpdated := False; @@ -228,14 +233,38 @@ begin KeyList[i + 1] := KeyList[i]; end; +{$IF FPC_FULLVERSION < 30000} +function IsClass(Instance: TObject; const ClassName: ShortString): Boolean; +var + ClassRef: TClass; +begin + Result := False; + ClassRef := Instance.ClassType; + while ClassRef <> nil do + begin + Result := ClassRef.ClassNameIs(ClassName); + if Result then + Exit; + ClassRef := ClassRef.ClassParent; + end; +end; +{$ENDIF} + procedure TDBLookup.FetchLookupData; var KeyIndex, KeyListCount: Integer; ListLinkDataSet: TDataSet; Bookmark: TBookmark; + {$IF FPC_FULLVERSION < 30000} + DatasetSupportsBlockRead: Boolean; + {$ENDIF} begin if not Assigned(FControlItems) then Exit; + {$IF FPC_FULLVERSION < 30000} + if FFetchingLookupData then + Exit; + {$ENDIF} FControlItems.Clear; ListLinkDataSet := FListLink.DataSet; if not (Assigned(ListLinkDataSet) and Assigned(FListField)) then @@ -243,11 +272,19 @@ begin if ListLinkDataSet.IsEmpty then Exit; Bookmark := ListLinkDataSet.GetBookmark; - {$ifdef EnableLookupWithBlockRead} + //in fpc 2.6.4, TMemDataset does not supports BlockRead. Issues 26356, 27959 + {$IF FPC_FULLVERSION < 30000} + DatasetSupportsBlockRead := not IsClass(ListLinkDataSet, 'TMemDataset'); + if DatasetSupportsBlockRead then + ListLinkDataSet.BlockReadSize := 1 + else + begin + FFetchingLookupData := True; + ListLinkDataSet.DisableControls; + end; + {$ELSE} ListLinkDataSet.BlockReadSize := 1; - {$else} - ListLinkDataSet.DisableControls; - {$endif} + {$ENDIF} FControlItems.BeginUpdate; try //needed to handle sqldb.TSQLQuery that does not has a reliable recordcount after Open @@ -273,11 +310,17 @@ begin FControlItems.EndUpdate; ListLinkDataSet.GotoBookmark(Bookmark); ListLinkDataSet.FreeBookmark(Bookmark); - {$ifdef EnableLookupWithBlockRead} + {$IF FPC_FULLVERSION < 30000} + if DatasetSupportsBlockRead then + ListLinkDataSet.BlockReadSize := 0 + else + begin + ListLinkDataSet.EnableControls; + FFetchingLookupData := False; + end; + {$ELSE} ListLinkDataSet.BlockReadSize := 0; - {$else} - ListLinkDataSet.EnableControls; - {$endif} + {$ENDIF} end; end;