我在用idlcmpclient1.ping循环ping几百个ip地址的时候,如何用一个按钮来终止这个事件???

解决方案 »

  1.   

    循环过程中加入这句试试
    Application.ProcessMessages;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Button2: TButton;
        procedure Button2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      tt:Boolean;
    implementation{$R *.DFM}procedure TForm1.Button2Click(Sender: TObject);
    begin
      tt:=true;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
     tt:=false;
     for i:= 0 to 100 do
     begin
      if tt then exit;
      edit1.Text:=inttostr(i);
      Application.ProcessMessages;
      sleep(100);
     end;
    end;end.
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        Button2: TButton;
        procedure Button2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      tt:Boolean;
    implementation{$R *.DFM}procedure TForm1.Button2Click(Sender: TObject);
    begin
      tt:=true;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
    begin
     tt:=false;
     for i:= 0 to 100 do
     begin
      if tt then exit;
      edit1.Text:=inttostr(i);
      Application.ProcessMessages;
      sleep(100);
     end;
    end;end.
      

  4.   

    循环过程中或循环外(在当前按钮中)加入
    Application.ProcessMessages;
    用以响应其它消息
    Break命令终止for、while、repeat循环语句 
      

  5.   

    我虽然不知道你的提问,但我觉得楼上两位的回答并不正确,Application.ProcessMessages;
    加上这句,能响应其他的事件,比如一个按钮的click事件,但如何在 click事件中如何终止这个循环,并没有给出解答。break只是退出本次循环,它在循环的内部,但却不能由其他的事件来触发。
      

  6.   


    定义全局变量tt
    再循环中判断tt
    Application.ProcessMessages;
    for i:=1 to 10000 do
    begin
      if tt=false then
         //执行代码
      else 
        break;  
    end;在另外一个按钮click事件中加入
    tt:=true;