在该程序执行的过程中,如果要关闭程序,请问我应该怎样操作?procedure TForm1.Button5Click(Sender: TObject);
var
j:integer;
begin
for j :=0 to 7 do
begin
        button1.onclick(button1);
        Delay(1000);
end;
end;如果直接关闭应用程序的话,程序要等循环终止才能关闭。我现在想在中途直接关闭程序。

解决方案 »

  1.   

    var b : Boolean  ;FormCreate    b := True ;
       
       
    procedure TForm1.Button5Click(Sender: TObject);
    var
    j:integer;
    begin
      for j :=0 to 7 do
      if b then 
        Delay(1000);
      else Application.Terminater ;
      Application.ProcessMessages ;
    end;
     
    procedure TForm1.Button5Click(Sender: TObject);
    begin
      b := False ;  
    end; 
      

  2.   

    你是说终止 Delay(1000) ? ,用线程
      

  3.   

    对,终止delay。
    线程怎么用?谢谢!
      

  4.   

    unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,UThTest;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      tt : TTest ;implementation
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      tt := TTest.Create(False);
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      TTest(tt).Terminate ;
      Caption := 'end ' ;
    end;
    end.-----------------------------------------------unit UThTest;interfaceuses
      windows,
      Classes;type
      TTest = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation{ Important: Methods and properties of objects in VCL or CLX can only be used
      in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TTest.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TTest }uses Unit1 ;procedure TTest.Execute;
    begin
      { Place thread code here }
      while not Terminated do Sleep(100000000) ;
    end;end.
      

  5.   

    抱歉,有点问题,这样-------------------------procedure TForm1.Button2Click(Sender: TObject);
    begin
      TerminateThread(TTest(tt).Handle,0);
      TTest(tt).Free ;
      Caption := 'end ' ;
    end;
      

  6.   

    抱歉,那个终止有点问题,没有完全释放掉,另写一个http://expert.csdn.net/Expert/topic/1383/1383761.xml?temp=.807873procedure TForm1.Button2Click(Sender: TObject);
    begin
      TerminateThread(TTest(tt).Handle,0);
      TTest(tt).Free ;
      Caption := 'end ' ;
    end;抱歉:)