![]() |
Hier mal der gesamte Quelltext:
Delphi-Quellcode:
Ich habe mal statt der Labels Shapes genommen. Das Formular ist im übrigen leer, weil die zehn Shapes und der Timer dynamisch erzeugt werden. Vielleicht könnte man daraus ja mal eine Komponente programmieren.
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. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:39 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz