我想在让程序在后台运行的时候,然后还可以响应其他事件
例如:
for i:=0 to 1000000000000 do
begin
   label1.caption:=IntToStr(i);
   label1.refresh;
end;那我想在这个程序运行过程中,可以让用户点Cancel按扭??????

解决方案 »

  1.   

    for i:=0 to 1000000000000 do
    begin
       label1.caption:=IntToStr(i);
       label1.refresh;
       Application.ProcessMessages;
    end;
      

  2.   

    var Term:Boolean
    for i:=0 to 1000000000000 do
    begin
       if Terl then Break;
       label1.caption:=IntToStr(i);
       label1.refresh;
    end;Btn_Cancel.clickTelr:=True;
      

  3.   

    1 设置一个变量b_cancel;
    在procedure tform1.cancelOnClick(...)
    begin
      b_cancel:= true;
    end;
    for i:=0 to 1000000000000 do
    begin
       label1.caption:=IntToStr(i);
       label1.refresh;
    if b_cancel then break;
    end;
      

  4.   

    WantT是窗体的私有变量procedure TForm1.Button1Click(Sender: TObject);
    Var
      I: Integer;
    begin
      For I := 0 To 10000000 Do
      begin
        Label1.caption:=IntToStr(i);
        Label1.refresh;
        Application.ProcessMessages;
        If WantT then
        Begin
          Break;
          WantT := False;
        End;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      WantT := True;
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      WantT := False;
    end;
      

  5.   

    WantT是窗体的私有变量procedure TForm1.Button1Click(Sender: TObject);
    Var
      I: Integer;
    begin
      For I := 0 To 10000000 Do
      begin
        Label1.caption:=IntToStr(i);
        Label1.refresh;
        Application.ProcessMessages;
        If WantT then
        Begin
          WantT := False;
          Break;
        End;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      WantT := True;
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      WantT := False;
    end;
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Label1: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        IsBreak:boolean;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
       i:integer;
    begin
      IsBreak:=False;
      for i:=0 to 1000000 do
        begin
           label1.caption:=IntToStr(i);
           label1.refresh;
           Application.ProcessMessages;
           if IsBreak then break;
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      IsBreak:=True;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      IsBreak:=False;
    end;end.上面程序在D6验证通过
      

  7.   

    1 设置一个变量b_cancel;
    在procedure tform1.cancelOnClick(...)
    begin
      b_cancel:= true;
    end;
    for i:=0 to 1000000000000 do
    begin
       label1.caption:=IntToStr(i);
       label1.refresh;
       Application.ProcessMessages;
    if b_cancel then break;
    end;
      

  8.   

    最简单的方法:
    for i:=0 to 1000000000000 do
    begin
       Application.ProcessMessages;
       label1.caption:=IntToStr(i);
       label1.refresh;
    end;
    楼上说不行的是瞎说,不要相信他
      

  9.   

    上面大家用的Application.ProcessMessages还是无法解决我的问题
    我不想中断一个而去执行另外一个程序,我需要两者同时运行其实在VB 中就很容易实现这个问题:DoEvents就搞定,无奈我是delphi菜鸟,请大家多多帮忙