Explorar o código

* Correct compare helper. Fix issue #41338

Michaël Van Canneyt hai 1 mes
pai
achega
8df634e335
Modificáronse 1 ficheiros con 18 adicións e 1 borrados
  1. 18 1
      rtl/objpas/sysutils/syshelps.inc

+ 18 - 1
rtl/objpas/sysutils/syshelps.inc

@@ -75,8 +75,25 @@ end;
 
 class function TStringHelper.Compare(const A: TStringType; const B: TStringType;
   Options: TCompareOptions): Integer;
+var
+  LenA,LenB : integer;
 begin
-  Result:=Compare(A,0,B,0,System.Length(B),Options);
+  LenB:=System.Length(B);
+  LenA:=System.Length(A);
+  if LenB=LenA then
+    Result:=Compare(A,0,B,0,LenB,Options)
+  else if (LenB>LenA) then
+    begin
+    Result:=Compare(A,0,B,0,LenA,Options);
+    if Result=0 then // over the length of A, both are equal.
+      Result:=-1;
+    end
+  else // lenB<LenA
+    begin
+    Result:=Compare(A,0,B,0,LenB,Options);
+    if Result=0 then     // Over the length of B, both are equal
+       Result:=1;
+    end;
 end;