When inserting new strings to the list, set the behavior of this TStringList class: ignore copies, add them, or mark as error.

 

This property works only if the string list is sorted.

 

Syntax

property TStringList.Duplicates: TDuplicates;

 

Parameters an return values

dupIgnore

ignore copies and do not add them to the list;

dupAccept

add any strings;

dupError

ignore copies and do not add them to the list by generating an error of adding an element. (use try...except).

 

Example


var
  SL: TStringList;
  
procedure FillList;
var 
  i: integer;
begin
   for i := 1 to 20 do 
     SL.Append(IntToStr(random(5)));
end;
begin
  SL := TStringList.Create;
  SL.Sorted := true;
  
  SL.Duplicates := dupAccept;
  FillList;
  mLogScript(SL.CommaText, 'Enable duplicates');
  
  SL.Clear;
  SL.Duplicates := dupIgnore;
  FillList;
  
  mLogScript(SL.CommaText, 'Disable duplicates');
  SL.Free;
end.


Script work result

[16:48:28] (Log "DuplicatesProperty"): [Enable duplicates] 0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,3,3,4,4,4

[16:48:28] (Log "DuplicatesProperty"): [Disable duplicates] 0,1,2,3,4

[16:48:28] (Run "DuplicatesProperty"): Script operation time: 5 ms

[16:48:28] (Run "DuplicatesProperty"): Script done successfully.

 

See also

IntToStr

mLogScript

Random

TStringList.Append

TStringList.Create

TStringList.CommaText

TStringList.Free

Created with the Personal Edition of HelpNDoc: Easy CHM and documentation editor