Browse Source

* Merging revisions r48711 from trunk:
------------------------------------------------------------------------
r48711 | michael | 2021-02-18 16:10:05 +0100 (Thu, 18 Feb 2021) | 1 line

* Fix from mattias Gartner for issue ID #38509, correctly rest index on close/reopen
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@49304 -

michael 4 years ago
parent
commit
08aeecc05d
1 changed files with 17 additions and 7 deletions
  1. 17 7
      packages/fcl-db/src/base/bufdataset.pas

+ 17 - 7
packages/fcl-db/src/base/bufdataset.pas

@@ -1449,6 +1449,7 @@ var
   i,r  : integer;
   iGetResult : TGetResult;
   pc : TRecordBuffer;
+  CurBufIndex: TBufDatasetIndex;
 
 begin
   FOpen:=False;
@@ -1498,10 +1499,17 @@ begin
   if FAutoIncValue>-1 then FAutoIncValue:=1;
   if assigned(FParser) then FreeAndNil(FParser);
   For I:=FIndexes.Count-1 downto 0 do
-    if (BufIndexDefs[i].IndexType in [itDefault,itCustom]) or (BufIndexDefs[i].DiscardOnClose) then
-       BufIndexDefs[i].Free
+    begin
+    CurBufIndex:=BufIndexDefs[i];
+    if (CurBufIndex.IndexType in [itDefault,itCustom]) or (CurBufIndex.DiscardOnClose) then
+      begin
+      if FCurrentIndexDef=CurBufIndex then
+        FCurrentIndexDef:=nil;
+      CurBufIndex.Free;
+      end
     else
-       FreeAndNil(BufIndexDefs[i].FBufferIndex);
+      FreeAndNil(CurBufIndex.FBufferIndex);
+    end;
 end;
 
 procedure TCustomBufDataset.InternalFirst;
@@ -3058,16 +3066,18 @@ function TCustomBufDataset.GetIndexFieldNames: String;
 var
   i, p: integer;
   s: string;
+  IndexBuf: TBufIndex;
 
 begin
   Result := FIndexFieldNames;
-  if (CurrentIndexBuf=Nil) then
+  IndexBuf:=CurrentIndexBuf;
+  if (IndexBuf=Nil) then
     Exit;
   Result:='';
-  for i := 1 to WordCount(CurrentIndexBuf.FieldsName, [Limiter]) do
+  for i := 1 to WordCount(IndexBuf.FieldsName, [Limiter]) do
   begin
-    s := ExtractDelimited(i, CurrentIndexBuf.FieldsName, [Limiter]);
-    p := Pos(s, CurrentIndexBuf.DescFields);
+    s := ExtractDelimited(i, IndexBuf.FieldsName, [Limiter]);
+    p := Pos(s, IndexBuf.DescFields);
     if p>0 then
       s := s + Desc;
     Result := Result + Limiter + s;