"For developers", "Server scripts", "Functions description", "Strings", "TStringList", "Methods", "Sort".

 

Sort the list by alphabetical order.

 

Syntax

procedure TStringList.Sort;

 

Example

function GetRandomText: string;
var
  x, y: integer;
  s1, s2: string;
begin
  x := random(7);
  y := random(7);
  
    case x of
      0: s1 := 'red';
      1: s1 := 'orange';
      2: s1 := 'yellow';
      3: s1 := 'green';
      4: s1 := 'blue';
      5: s1 := 'dark-blue';
      6: s1 := 'purple';
    end;
    case y of
      0: s2 := 'bull';
      1: s2 := 'rooster';
      2: s2 := 'gopher';
      3: s2 := 'cat';
      4: s2 := 'stork';
      5: s2 := 'bear';
      6: s2 := 'ostrich';
    end;
  result := s1 + ' ' + s2;
end;
var
  SL: TStringList;
  i: integer;
begin
  SL := TStringList.Create;
  
    for i := 1 to 10 do SL.Append(GetRandomText);
  
  mLogScript(CRLF + SL.Text, 'Unsorted');
  
  SL.Sort;
  
  mLogScript(CRLF + SL.Text, 'Sorted');
  
  SL.Free;
end.


Script work result

[17:00:13] (Log "SortMethod"): [Unsorted]

purple bull

red rooster

dark-blue cat

orange ostrich

red gopher

dark-blue stork

red cat

blue bear

orange stork

yellow stork

[17:00:13] (Log "SortMethod"): [Sorted]

blue bear

dark-blue cat

dark-blue stork

orange ostrich

orange stork

purple bull

red rooster

red gopher

red cat

yellow stork

[17:00:13] (Run "SortMethod"): Script operation time: 6 ms

[17:00:13] (Run "SortMethod"): Script done successfully.

 

See also

CRLF

mLogScript

Random

TStringList.Append

TStringList.Create

TStringList.Free

TStringList.Text