TStringList.Add

From Soldat Community Wiki
Revision as of 16:38, 23 August 2013 by Mighty (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function Add(S: string): Integer
 S: string to be added
 Result: Strings[] index with newly added string

Description

This function will add S to the list. Note that Duplicates affects the function.
If the list is sorted and the string S is already present in the list and Duplicates is dupError then an error occurs.
If Duplicates is set to dupIgnore then the return value is underfined.

If the list is sorted, new strings will not necessarily be added to the end of the list, rather they will be inserted at their alphabetical position.

Example

var
  s: TStringList;

begin
  s := File.CreateStringList();
  s.Add('b');
  s.Add('a');
  s.Add('d');
  WriteLn(s.Text);
{
b
a
d

}

  s.Add('c');
  WriteLn(s.Text);
{
b
a
d
c

}
  
  s.Sort;
  s.Sorted := TRUE; 
  // necessary if you want further values to be sorted as well
  s.Duplicates := dupIgnore;
  
  WriteLn(s.Text);
{
a
b
c
d

}
  
  
  s.Add('c'); // this will be ignored (s.Duplicates = dupIgnore)
  s.Add('aa');
  
  WriteLn(s.Text);
{
a
aa
b
c
d

}
  
  s.Free;
end.