I have copied the code below from a tutorial.
It should allow 5 balls to bounce around on the screen within the form.
It works on the video but I get this error. (See attachment)
It compiles ok yet fails to run.
I did try and remake it from the tutorial code but have obviously got it wrong somewhere.
What have I missed ?
Thanks
Using Laz 1.6 FPC ver 3 x86-64-Win64-win32/win64
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Shape1: TShape;
Shape2: TShape;
Shape3: TShape;
Shape4: TShape;
Shape5: TShape;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
Balls: Array [1..5] of TShape;
Right: Array [1..5] of Boolean;
Up: Array [1..5] of Boolean;
x: Integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Timer1Timer(Sender: TObject);
begin
for x := 1 to 5 Do
Begin
if Up[x] = True then Balls[x].Top:=Balls[x].Top-5
else Balls[x].Top:=Balls[x].Top+5;
if Right[x] = True then Balls[x].Left:=Balls[x].Left+5
else Balls[x].Left:=Balls[x].Left-5;
if Balls[x].Top <= 0 then Up[x] := False;
if Balls[x].Top + Balls[x].Height >= Form1.Height then Up[x] := True;
if Balls[x].Left <= 0 then Right[x] := True;
if Balls[x].Left + Balls[x].Width >= Form1.Width then Right[x] :=False;
end;
end;
end.