我用timer 定时触发一个button事件,但是在程序运行中确无法关闭 窗体 谢谢了 急

解决方案 »

  1.   

      检查button事件中是否有无限循环。
      类似于下面这样的代码会出现无法关闭窗口的情况。
      
      procedure Tform1.button1click(sender:tobject)
      while true do
      begin 
       button1.caption:=2;
       application.processmessage;
      end;
      
      即使是写了processmessage依然是关闭不了窗口的。
      

  2.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Form1.Close;
    end;自行设定timer1的Interval值,等时间到了设定的时候,就会触发以上事件
    D7下通过
      

  3.   

    參考之
    unit Unit1;interfaceuses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ExtCtrls, StdCtrls;type
    TForm1 = class(TForm)
    Button1: TButton;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    end;var
    Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    Timer1.Interval := 15000; {定时器每 15 秒执行一次}
    Timer1.Enabled := False; {定时器默认是直接启动的, 先关闭它}
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    {启动定时器}
    Timer1.Enabled := True;
    {点击按钮是什么功能呢? 譬如是让按钮标题自动计数}
    Button1.Caption := IntToStr(StrToIntDef(Button1.Caption, 0) + 1);
    end;{定时去执行 Button1Click}
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    Button1.Click;
    end;end.
      

  4.   

    button跟窗口有什么关系?估计有其它问题
      

  5.   

    所执行的是单一线程,因线程未执行完,消息传递未及时,所以出现假死.建议使用多线程代替TIMER
      

  6.   


    procedure TForm1.Button9Click(Sender: TObject);                           //立即关闭
    begin
      ExitProcess(0);
      Application.Terminate;
    end;