Embarcadero Delphi TStringList class Introduction


Example

TStringList is a descendant of the TStrings class of the VCL. TStringList can be used for storing and manipulating of list of Strings. Although originally intended for Strings, any type of objects can also be manipulated using this class.

TStringList is widely used in VCL when the the purpose is there for maintaining a list of Strings. TStringList supports a rich set of methods which offer high level of customization and ease of manipulation.

The following example demonstrates the creation, adding of strings, sorting, retrieving and freeing of a TStringList object.

procedure StringListDemo;
var 
   MyStringList: TStringList;
   i: Integer;

Begin

   //Create the object
   MyStringList := TStringList.Create();
   try
      //Add items
      MyStringList.Add('Zebra');
      MyStringList.Add('Elephant');
      MyStringList.Add('Tiger');

      //Sort in the ascending order
      MyStringList.Sort;

      //Output 
      for i:=0 to MyStringList.Count - 1 do
        WriteLn(MyStringList[i]);
   finally
      //Destroy the object
      MyStringList.Free;
   end;
end;

TStringList has a variety of user cases including string manipulation, sorting, indexing, key-value pairing and delimiter separation among them.