TStringList.Sort

From Soldat Community Wiki
Jump to: navigation, search
procedure Sort()

Description

This function will sort strings in TStringList alphabetically.
Note that this doesn't set Sorted to TRUE, so if you plan to add more strings and don't want to break the sorting, you have to set it to TRUE manually.

Example

var
  s: TStringList;

begin
  s := File.CreateStringList();
  s.Append('d');
  s.Append('a');
  s.Append('c');
  s.Append('ca');
  s.Append('b');

  WriteLn(s.CommaText);
  // d,a,c,ca,b 

  s.Sort();

  WriteLn(s.CommaText);
  // a,b,c,ca,d

  s.Free;
end.