[ Back to the overview Matrix ]

Test case : Sort 2 using Delphi 6

Lines used: 15
(This is pretty similar to the type example, and pretty trivial, as Tstringlist supports sorting)
         
  [Create a new console application. In some versions of Delphi, you will need 
  to create a normal application, strip all forms, and add {$APPTYPE CONSOLE} in 
  the project source under "program"]
  
uses
  SysUtils,classes;                    {add classes to the used units to get TStringlist}

var                                    {variable declaration}
  fil:TStringlist;                     {a list of strings for the file}
  n:integer;                           {a whole number variable to step through the lines}

begin                                  {begin of main block}
  fil:=TStringlist.create;             {create the string list object}
  fil.loadfromfile(paramstr(1));       {load the textfile specified as first parameter into the list} 
  fil.Sort;                            {sort the lines in ascending order}
  fil.savetofile('sorted.txt');        {save them to a file }
  FreeAndNil(fil);                     {free the list}
end.                                   {end of main block}
Contributed by Andreas Koch, mail at kochandreas.com