
15.05.2008, 19:54
|
Модератор
|
|
Регистрация: 17.04.2008
Сообщения: 8,097
Версия Delphi: 7, XE3, 10.2
Репутация: 49089
|
|
Ну ты и маньяк!!!
Как ты собрался таймеры-о синхронизировать???
На, смотри как надо делать.
1 таймер и одна процедура отрисовки. В событии таймера либо инициализируем массив из констант, либо просто перемещаем элементы массива по кольцу на 1 шаг.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
AColors : Array Of TColor;
public
{ Public declarations }
procedure DrawColors(ARect : TRect; AColors : Array Of TColor);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
DefColors : Array [0..6] Of TColor = (clRed, clGreen, clGray, clYellow, clBlack, clNavy, clMaroon);
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := Not Timer1.Enabled;
end;
procedure TForm1.DrawColors(ARect: TRect; AColors : Array Of TColor);
var
I : Integer;
R : TRect;
begin
For I := Low(AColors) To High(AColors) Do
Begin
R := Rect(ARect.Left,
ARect.Top + I * Round((ARect.Bottom - ARect.Top)/Length(AColors)),
ARect.Right,
ARect.Top + (I + 1) * Round((ARect.Bottom - ARect.Top)/Length(AColors)));
Self.Canvas.Brush.Color := AColors[i];
Self.Canvas.FillRect(R);
End;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
I : Integer;
C : TColor;
begin
If Length(AColors) = 0
Then
Begin
// First run
SetLength(AColors, Length(DefColors));
For I := Low(DefColors) To High(DefColors) Do AColors[i] := DefColors[i];
End
Else
Begin
C := AColors[Low(AColors)];
For I := Low(AColors) To High(AColors)-1 Do
Acolors[i] := AColors[I+1];
AColors[High(AColors)] := C;
End;
DrawColors(Rect(100,100,300,200),AColors);
end;
end.
|