Преглед на файлове

* Fix from Werner Pamler to fix locate. Fixes issue #40748

Michaël Van Canneyt преди 1 година
родител
ревизия
0d71273adc
променени са 1 файла, в които са добавени 37 реда и са изтрити 33 реда
  1. 37 33
      packages/fcl-db/src/dbase/dbf.pas

+ 37 - 33
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
-    begin
-      FCursor.Free;
-      FCursor := lSaveCursor;
-    end;
-    if lIndexFile <> nil then
+    if lCursor <> 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;