Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi einfaches lauflicht? (https://www.delphipraxis.net/5053-einfaches-lauflicht.html)

[Flox]Cauchy 24. Mai 2003 00:01

Hier mal der gesamte Quelltext:
Delphi-Quellcode:
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.
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:49 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz