Programs to Debug: Number 8

We suggest that you inspect this program to see if you can spot the errors before attempting to compile it in Delphi or Lazarus. Make the necessary changes so that each program will compile and achieve the stated purpose. Our pages on common programming errors may help you.

program Display;
{$APPTYPE CONSOLE}
{This program should show 4 lines in total of centred
 output, separated by blank lines to clear the screen.
 There are two deliberate errors.}
uses
  SysUtils;
const
  Texts : array[1..3] of string = ('Start of centred output',
                    'Followed by blank lines to clear the screen',
                    'More centred text');
var
  LineCount : integer;

procedure InsertLines(InsertNum : real);
var
  i : integer;
begin
  for i := 1 to InsertNum do writeln;
end;

procedure CentreText(Width : integer; TextLine: string);
var
  LeftSpaces, i : integer;
begin
  LeftSpaces := (Width - length(TextLine)) div 2;
  for i:=1 to LeftSpaces do TextLine := ' ' + TextLine;
  writeln(TextLine);
end;

begin
  for LineCount := 1 to 3 do
  begin
    CentreText(Texts[LineCount], 80);
    sleep(2000);
    InsertLines(30);
  end;
   CentreText(80, 'End of output');
   readln;
end.
Programming - a skill for life!

Spot the deliberate errors