stringlistcontainer Add method
Return to Introduction  Previous page  Next page
Applies to
acStringListContainer component.  

function Add(const S: String): Integer;  

The Add method adds a new string to the list.  
Call Add to add the string S to the end of the list. If the list is not sorted, S is added to the end of the list. Add returns the position of the item in the list, where the first item in the list has a value of 0.  
iiinfo The Add adds the string to the end of the list. If you would like to insert the string to some particular position of the list — use Insert method instead.  
iiwarning Add will raise an EListError exception if the string S already appears in the list and Duplicates is set to dupError. If Duplicates is set to dupIgnore, trying to add a duplicate string does nothing.  
iiwarning Note that the list can't contain more strings than the number specified in the MaxSize property. For example, if MaxSize = 100 and you're trying to add 101st string, the first string will be deleted from the list to allow the new string to be added.  

procedure TForm1.FormCreate(Sender: TObject);  
  MyList: TacStringList;  
  Index: Integer;  
  MyList := TacStringList.Create;  
    if MyList.Find('Flowers', Index) then  
      Label1.Caption := 'Flowers has an index value of ' + IntToStr(Index);  

See also
Insert and AddStrings methods;  
Duplicates and MaxSize properties;  
OnChange event.