就像路口的红灯绿灯那样,能变颜色,能闪烁,求教高手!
解决方案 »
- 我用canvas跟别人的圆不一样,有毛刺
- select
- 这样做会发生内存漏失吗
- 在delphi中,如何跟数据库相连啊,以前在VB中我们在DLL中创建了个连接类,然后在程序中调用就可以了,delphi中该怎么做啊??
- 糖厂的地磅。没有接触过!!!
- 如何更改窗口的主菜单高度?
- 谁有APPBAR FOR DELPHI6的构件啊,要有源码的。多谢谢。(OFFICE PANEL)
- 我用delphi编写asp应用,dll一旦调入内存,如何关闭? 我现在只有启动计算机.有没有更好的办法?(在线等待)
- iis错错误
- 我写一个COM组件在自动类中用到了这个:varArraycreate([0,FContentLength],varByte);编译过程中提示:Undeclared identifer:'vararraycreate'请问是否需要在USES中包含特别的单元?
- 一个关于得到IP地址的小问题!
- 求助!将java代码翻译成delphi代码!简单的几句
方法2:作一个gif文件,播放它.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,LightU;type
TInvokF = class(TForm)
Button1: TButton;
TimerShow: TTimer;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure TimerShowTimer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
InvokF: TInvokF;
FLight:array[1..4] of TLight;
Duration:array[1..3] of byte;
WhichColor:byte;
State:byte;
implementationuses Math;{$R *.dfm}procedure TInvokF.Button1Click(Sender: TObject);
var
i:integer;
begin
For i:=1 to 4 do
begin
FLight[i]:=TLight.Create(self);
with FLight[i] do
begin
Left:=80*i;
Top:=30;
Width:=50;
Height:=50;
Parent:=InvokF;
Shape:=stCircle;
Brush.Color :=clBtnFace;
end;
end;
//
//FLight[1].Left :=160;
//FLight[4].top:=154;
//FLight[2].Visible:=false;
//FLight[3].Visible:=false;
//
State:=0;
Duration[1]:=0;
FLight[1].Duration:=5;
FLight[2].Duration:=2;
FLight[3].Duration:=5;
WhichColor:=Random(271) mod 4;
if WhichColor=0 then WhichColor:=1;
TimerShow.Enabled:=true;
//Timer1.Enabled:=true;
//
Canvas.Pen.Width:=16;
Canvas.MoveTo(0,round(Self.height/2));
Canvas.LineTo(self.Width ,round(Self.height/2));
Canvas.MoveTo(round(Self.Width /2),0);
Canvas.LineTo(round(Self.Width /2),self.height);
end;procedure TInvokF.TimerShowTimer(Sender: TObject);
begin
case WhichColor of
1: begin
Caption:='红灯 '+inttostr(FLight[1].Duration)+' 秒 '+inttostr(Duration[1]);
FLight[1].Brush.Color:=clRed; if Duration[1] >=FLight[1].Duration then
begin
Duration[1]:=0;
FLight[1].Brush.Color:=clBtnShadow;
FLight[2].Brush.Color:=clYellow;
WhichColor:=2;
State:=0;
end
else
Duration[1]:=Duration[1]+1;
end;
2: begin
Caption:='黄灯 '+inttostr(FLight[2].Duration)+' 秒 '+inttostr(Duration[2]);
if Duration[2] >=FLight[2].Duration then
begin
Duration[2] :=0;
FLight[2].Brush.Color:=clBtnShadow;
case State of
0: begin
FLight[3].Brush.Color:=clGreen;
WhichColor:=3;
end;
1: begin
FLight[1].Brush.Color:=clRed;
WhichColor:=1;
end;
end;
end
else
Duration[2]:=Duration[2]+1;
end;
3: begin
Caption:='绿灯 '+inttostr(FLight[3].Duration)+' 秒 '+inttostr(Duration[3]);
if Duration[3]>=FLight[3].Duration then
begin
Duration[3]:=0;
FLight[3].Brush.Color:=clBtnShadow;
FLight[2].Brush.Color:=clYellow;
WhichColor:=2;
State:=1;
end
else
Duration[3]:=Duration[3]+1;
end;
end;
end;
procedure TInvokF.Timer1Timer(Sender: TObject);
begin
case WhichColor of
1: begin
Caption:='红灯 '+inttostr(FLight[1].Duration)+' 秒 '+inttostr(Duration[1]);
FLight[1].Brush.Color:=clRed;
FLight[4].Brush.Color:=clGreen;
if Duration[1] >=FLight[1].Duration then
begin
Duration[1]:=0;
FLight[1].Brush.Color:=clYellow;
FLight[4].Brush.Color:=clYellow;
WhichColor:=2;
State:=0;
end
else
Duration[1]:=Duration[1]+1;
end;
2: begin
Caption:='黄灯 '+inttostr(FLight[2].Duration)+' 秒 '+inttostr(Duration[2]);
if Duration[2] >=FLight[2].Duration then
begin
Duration[2] :=0;
FLight[1].Brush.Color:=clBtnShadow;
case State of
0: begin
FLight[1].Brush.Color:=clGreen;
WhichColor:=3;
FLight[4].Brush.Color:=clRed;
end;
1: begin
FLight[1].Brush.Color:=clRed;
WhichColor:=1;
FLight[4].Brush.Color:=clGreen;
end;
end;
end
else
Duration[2]:=Duration[2]+1;
end;
3: begin
Caption:='绿灯 '+inttostr(FLight[3].Duration)+' 秒 '+inttostr(Duration[3]);
if Duration[3]>=FLight[3].Duration then
begin
Duration[3]:=0;
FLight[1].Brush.Color:=clYellow;
FLight[4].Brush.Color:=clYellow;
WhichColor:=2;
State:=1;
end
else
Duration[3]:=Duration[3]+1;
end;
end;
/////////////////
end;end.
------------------
unit LightU;interface
uses ExtCtrls;
Type
TLight=class(TShape)
private
FDuration: integer;
procedure SetDuration(const Value: integer);
public
property Duration:integer read FDuration write SetDuration default 20; end;implementationuses Controls;{ TLight }procedure TLight.SetDuration(const Value: integer);
begin
FDuration := Value;
end;
end.
-----------
界面上放2个timer一叫timer1,另一个TimerShow,还有一个button1