Browse Source

* Fix behaviour of AddObject when duplicates=dupIgnore. Patch by Artem Izmaylov. Fixes issue #40898

Michaël Van Canneyt 11 months ago
parent
commit
d3c902e5a1
2 changed files with 9 additions and 2 deletions
  1. 1 0
      rtl/objpas/classes/classesh.inc
  2. 8 2
      rtl/objpas/classes/stringl.inc

+ 1 - 0
rtl/objpas/classes/classesh.inc

@@ -1139,6 +1139,7 @@ type
     Constructor Create(anOwnsObjects : Boolean);
     Constructor Create(anOwnsObjects : Boolean);
     destructor Destroy; override;
     destructor Destroy; override;
     function Add(const S: string): Integer; override;
     function Add(const S: string): Integer; override;
+    function AddObject(const S: string; AObject: TObject): Integer; override;
     procedure Clear; override;
     procedure Clear; override;
     procedure Delete(Index: Integer); override;
     procedure Delete(Index: Integer); override;
     procedure Exchange(Index1, Index2: Integer); override;
     procedure Exchange(Index1, Index2: Integer); override;

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

@@ -1939,16 +1939,22 @@ end;
 
 
 function TStringList.Add(const S: string): Integer;
 function TStringList.Add(const S: string): Integer;
 
 
+begin
+  Result := AddObject(S, nil);
+end;
+
+function TStringList.AddObject(const S: string; AObject: TObject): Integer;
+
 begin
 begin
   If (SortStyle<>sslAuto) then
   If (SortStyle<>sslAuto) then
     Result:=FCount
     Result:=FCount
   else
   else
     If Find (S,Result) then
     If Find (S,Result) then
-      Case DUplicates of
+      Case Duplicates of
         DupIgnore : Exit;
         DupIgnore : Exit;
         DupError : Error(SDuplicateString,0)
         DupError : Error(SDuplicateString,0)
       end;
       end;
-   InsertItem (Result,S);
+   InsertItem (Result,S,AObject);
 end;
 end;
 
 
 procedure TStringList.Clear;
 procedure TStringList.Clear;