当点了在form1窗体里按钮,执行了while循环工作 
while i<10000 then 
begin 
i:=i+1; 
end; 
,并show出form2窗体然后过五秒样子再点form2窗体按钮来中止form1窗体里的while循环再点form1窗体按钮弹出消息“完成”。 我不要通过关闭form1窗体进程方式,谁写出来这个代码来呢?

解决方案 »

  1.   

    设置一个变量
    while i <10000 then 
    begin
      if 变量 = True
        break
      i:=i+1; 
    end; 
      

  2.   

    这个变量要是从Form2窗体给过来。传递不了。被while占用了不让你传递。只有它执行完才有可以做其它事情。
      

  3.   

    发消息,form2发消息,form1接收或者在while循环中加上application.ProcessMessages,移交控制权
      

  4.   

    var
      Loop_out: Boolean; //全局变量
    var
      I: Integer;
    label
      outer;
    begin
      I := 1;
      while i <10000 then 
      begin 
        i:=i+1; 
        if Loop_out then //通过FORM2来改变
           goto outer 
      end;   outer:
        ShowMessage('完成');
    end;
      

  5.   

    定义一个全局变量:
    var
      bExitFor : Boolean;Form1中:
    bExitFor := False;
    while i <10000 then 
    begin 
      Application.ProcessMessages;   //得加上这一句
      if bExifFor then break;
      i:=i+1; 
    end;Form2中:
    ......
    bExitFor := True;
    ......
      

  6.   

    3楼正解,关键在:application.ProcessMessages