[ Back to the overview Matrix ]

Test case : Type "file" using Delphi 6

Lines used: 15
(i used an object orientated approach. You could also use the TP7 example with minor keyword modifications.)
         
  [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} 
  for n:=1 to fil.count-1 do           {go through all elements of the list}
    writeln(fil[n]);                   {write the current line}
  FreeAndNil(fil);                     {free the list}
end.                                   {end of main block}
Contributed by Andreas Koch, mail at kochandreas.com