刚开始学delphi  书上关于timer控件就几句话过去了 看起来也挺简单的 但是今天用起来才发现,我不知道什么时候设置enabled什么时候是true什么时候是false;比如说 最简单的:我想要让label1.caption:='hello!';
那么我应该在buttonclick中写什么?在timerTimer中写什么?书上说timer里要写要做的事情,那么button里什么都不写了么?大家都说说看 我刚开始学 哥哥姐姐们随便说句话也都是我的经验啊 还希望不吝赐教 谢谢大家了

解决方案 »

  1.   

    设置Enabeled :=Ture就相当于开始了,每隔一段时间就执行TimerTimer中的代码。
      

  2.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        Button1: TButton;
        Label1: TLabel;
        procedure Timer1Timer(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    var
      i :Integer;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      Timer1.Enabled :=True;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      i :=i+1;
      Label1.Caption :=IntToStr(i);
    end;end.
      

  3.   

    楼上正确啊,其实只写
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
       Label1.Caption :='Hello!';
    end;
    就行了,然后可以手动设置timer1.Enabled属性为True,楼上的按钮事件是用程序实现的,就是点完按钮自动执行
    Timer1Timer事件了,当然如果你默认设置是1秒钟后看到程序执行结果,如果想设置间隔的话,设置Inteval属性,里面是毫秒,例如1000是1秒钟。
      

  4.   

    false不用写么?true和false不是一定要写的么?例子我看明白了,但是在复杂点就不怎么会了、、看来还得多做练习吧
      

  5.   

    Timer创建出来默认是True的!!!所以2楼的在没有点击按钮的时候也会执行