有关TIMER的小问题!!!(0分)

  • 主题发起人 主题发起人 百事
  • 开始时间 开始时间

百事

Unregistered / Unconfirmed
GUEST, unregistred user!
请大家帮忙看一下这段小程序,我需要的是在间隔3秒钟的时间动态的描绘一个点,但是
它就只隔了三秒之后就把所有的点都描绘出来了,我对TIMER不怎么熟悉,大家请指教!!
先谢谢了!

procedure TForm1.Button1Click(Sender: TObject);
begin
image1.Canvas.MoveTo(0,150);
image1.Canvas.Pen.Width:=3;
image1.Canvas.LineTo(600,150);
image1.Canvas.MoveTo(0,150);
timer1.Enabled:=true;

end;



procedure TForm1.Timer1Timer(Sender: TObject);
var i:integer;
begin
timer1.Enabled:=false;
for i:=0 to 60 do
begin
timer1.Enabled:=true;
timer1.Interval:=3000;
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);
end;
end;
end.
 
for.. 里面的timer1.Enabled:=true;不要。
 
同样出错,我觉得在开头为FALSE了,在FOR里面要控制时间应该要为TRUE才对,请多给点
意见,谢谢!!!
 
procedure TForm1.Timer1Timer(Sender: TObject);
begin
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(tag*10,150);
tag := tag + 1;
if tab = 60 then Timer1.Enabled := false;
end;
 
不要for循环
timer1.Interval:=3000;在设计界面输入

procedure TForm1.Timer1Timer(Sender: TObject);
var i:integer;
begin
timer1.Enabled:=false;

image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);

timer1.Enabled:=true;
end;
 
TO breezee:
这样也不行,我这样做了,还是不行,还有就是怎么来限定I的值 ,我只要它在0-60之间
请多给点意见,谢谢!
 
去掉循环
var i:integer; 定义为全局的;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Enabled:=false;
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);
i++;
timer1.Enabled:=true;
end;
 
i++ 可以吗?
 
方法一、
在time控件中将触发时间设为1000
var i:integer; 定义为全局的;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(i);
if i mod 3=0 then
begin
i:=0;
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);
end;
end;
方法二、
在time控件中将触发时间设为3000
procedure TForm1.Timer1Timer(Sender: TObject);
begin
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);
end;

 
前面方法一中的image1.Canvas.LineTo(i*10,150);中的变量i要换成其他变量如j
 
implementation

var
i:integer;

procedure TForm1.Button1Click(Sender: TObject);
begin
image1.Canvas.MoveTo(0,150);
image1.Canvas.Pen.Width:=3;
image1.Canvas.LineTo(600,150);
image1.Canvas.MoveTo(0,150);
timer1.Enabled:=true;
i:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin
i:=i+1;
if i<=60 then
begin
timer1.Interval:=3000;
image1.Canvas.Pen.Width:=3;
image1.Canvas.Pen.Color:=clred;
image1.Canvas.LineTo(i*10,150);
end;
end;

end.
 
很谢谢大家了,问题解决了。

procedure TForm1.Timer2Timer(Sender: TObject);
begin
timer2.Enabled:=false;
if not (i=120)
then
begin
i:=i+1;
image7.Canvas.Pen.Width:=3;
image7.Canvas.Pen.Color:=clred;
image7.Canvas.LineTo(i*5,261-strtoint(edit1.Text));
timer2.Enabled:=true;
timer2.Interval:=15000;
end;
end;

在前面把I:=0,这样就实现了。

小女子在这里谢谢大家了!!!
 
后退
顶部