unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TFormMain =
class(TForm)
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure TimerMoveLightsTimer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
FormMain: TFormMain;
implementation
{$R *.DFM}
type
TMoveLights =
record
Position: Byte;
Shapes:
array[0..9]
of TShape;
Timer: TTimer;
end;
var
MoveLights: TMoveLights;
procedure MoveLightsInit;
var
i: Byte;
begin
for i := 0
to 9
do
begin
MoveLights.Shapes[i] := TShape.Create(FormMain);
with MoveLights.Shapes[i]
do
begin
Left := 20 + i*20;
Top := 20;
Width := 20;
Height := 20;
Shape := stCircle;
Parent := FormMain;
end;
end;
for i := 0
to 2
do
MoveLights.Shapes[i].Brush.Color := clRed;
for i := 3
to 9
do
MoveLights.Shapes[i].Brush.Color := clBlack;
MoveLights.Position := 1;
MoveLights.Timer := TTimer.Create(FormMain);
MoveLights.Timer.Interval := 250;
MoveLights.Timer.OnTimer := FormMain.TimerMoveLightsTimer;
end;
procedure MoveLightsFree;
var
i: Byte;
begin
MoveLights.Timer.Free;
for i := 0
to 9
do
MoveLights.Shapes[i].Free;
end;
procedure MoveLightsRight;
begin
with MoveLights
do
begin
Shapes[(Position+9)
mod 10].Brush.Color := clBlack;
Position := (Position+1)
mod 10;
Shapes[(Position+1)
mod 10].Brush.Color := clRed;
end;
end;
procedure MoveLightsLeft;
begin
with MoveLights
do
begin
Shapes[(Position+1)
mod 10].Brush.Color := clBlack;
Position := (Position+9)
mod 10;
Shapes[(Position+9)
mod 10].Brush.Color := clRed;
end;
end;
procedure TFormMain.FormShow(Sender: TObject);
begin
MoveLightsInit;
end;
procedure TFormMain.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
MoveLightsFree;
end;
procedure TFormMain.TimerMoveLightsTimer(Sender: TObject);
begin
MoveLightsRight;
end;
end.