Browse Source

* Allow Reverse to be used on Self. Copy objects as well. Fixes issue #41508

Michaël Van Canneyt 3 weeks ago
parent
commit
4585fe4323
1 changed files with 27 additions and 2 deletions
  1. 27 2
      rtl/objpas/classes/stringl.inc

+ 27 - 2
rtl/objpas/classes/stringl.inc

@@ -423,10 +423,35 @@ Procedure TStrings.Reverse(aList : TStrings);
 
 Var
   I : Integer;
+  lList : TStrings;
 
 begin
-  for I:=Count-1 downto 0 do
-    aList.Add(Strings[i]);
+  if aList=self then
+    begin
+    lList:=Nil;
+    BeginUpdate;
+    try
+      lList:=TStringList.Create;
+      Reverse(lList);
+      AddStrings(lList,True);
+    finally
+      EndUpdate;
+      lList.Free;
+    end;
+    end
+  else 
+    begin
+    aList.BeginUpdate;
+    try
+      aList.Clear;
+      if aList.Capacity<Self.Count then
+        aList.Capacity:=Self.Count;
+      for I:=Count-1 downto 0 do
+        aList.AddObject(Strings[i],Objects[i]);
+    finally
+      aList.EndUpdate;
+    end;      
+    end;  
 end;