From 0d71273adcf9880eee765ad2f73b35854f356371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Thu, 27 Jun 2024 16:42:20 +0200 Subject: [PATCH] * Fix from Werner Pamler to fix locate. Fixes issue #40748 --- packages/fcl-db/src/dbase/dbf.pas | 70 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/packages/fcl-db/src/dbase/dbf.pas b/packages/fcl-db/src/dbase/dbf.pas index 9184b90c3e..a923138cef 100644 --- a/packages/fcl-db/src/dbase/dbf.pas +++ b/packages/fcl-db/src/dbase/dbf.pas @@ -2066,45 +2066,49 @@ var lIndexDef: TDbfIndexDef; lIndexFile, lSaveIndexFile: TIndexFile; begin - lCursor := nil; - lSaveCursor := nil; - lIndexFile := nil; - lSaveIndexFile := FIndexFile; - if (FCursor is TIndexCursor) - and (TIndexCursor(FCursor).IndexFile.Expression = KeyFields) then + if not (loCaseInsensitive in Options) then begin - lCursor := FCursor; - end else begin - lIndexDef := FIndexDefs.GetIndexByField(KeyFields); - if lIndexDef <> nil then + lCursor := nil; + lSaveCursor := nil; + lIndexFile := nil; + lSaveIndexFile := FIndexFile; + if (FCursor is TIndexCursor) + and (TIndexCursor(FCursor).IndexFile.Expression = KeyFields) then begin - lIndexName := ParseIndexName(lIndexDef.IndexFile); - lIndexFile := FDbfFile.GetIndexByName(lIndexName); - if lIndexFile <> nil then + lCursor := FCursor; + end else begin + lIndexDef := FIndexDefs.GetIndexByField(KeyFields); + if lIndexDef <> nil then begin - lSaveCursor := FCursor; - lCursor := TIndexCursor.Create(lIndexFile); - lSaveIndexName := lIndexFile.IndexName; - lIndexFile.IndexName := lIndexName; - FIndexFile := lIndexFile; + lIndexName := ParseIndexName(lIndexDef.IndexFile); + lIndexFile := FDbfFile.GetIndexByName(lIndexName); + if lIndexFile <> nil then + begin + lSaveCursor := FCursor; + lCursor := TIndexCursor.Create(lIndexFile); + lSaveIndexName := lIndexFile.IndexName; + lIndexFile.IndexName := lIndexName; + FIndexFile := lIndexFile; + end; end; end; - end; - if lCursor <> nil then - begin - FCursor := lCursor; - Result := LocateRecordIndex(KeyFields, KeyValues, Options); - if lSaveCursor <> nil then + if lCursor <> nil then begin - FCursor.Free; - FCursor := lSaveCursor; - end; - if lIndexFile <> nil then - begin - FLocateRecNo := FIndexFile.PhysicalRecNo; - lIndexFile.IndexName := lSaveIndexName; - FIndexFile := lSaveIndexFile; - end; + FCursor := lCursor; + Result := LocateRecordIndex(KeyFields, KeyValues, Options); + if lSaveCursor <> nil then + begin + FCursor.Free; + FCursor := lSaveCursor; + end; + if lIndexFile <> nil then + begin + FLocateRecNo := FIndexFile.PhysicalRecNo; + lIndexFile.IndexName := lSaveIndexName; + FIndexFile := lSaveIndexFile; + end; + end else + Result := LocateRecordLinear(KeyFields, KeyValues, Options); end else Result := LocateRecordLinear(KeyFields, KeyValues, Options); end;