var
  ExitFlag:Boolean;
ExitFlag初始为False~~~当按键事件发生以后~~修改为True~~for i:=1 to 5000 do
begin
  windows.beep(300+i,500);
  if ExitFlag=True then exit;
end;

解决方案 »

  1.   

    正如tikkypeng(一两狂死郎之天衣有缝)所说
    在onkeydown中
    exitflag:=true;
    for i:=1 to 5000 do
    begin
      windows.beep(300+i,500);
      if ExitFlag=True then 
      begin
        exitflag:=false;
        exit;
      end;
    end; 
      

  2.   

    to 以上各位在循环内部加application.ProcessMessages 应该有必要吧
      

  3.   

    for i:=1 to 5000 do
    begin
      windows.beep(300+i,500);
      Application.ProcessMessages;
      if ExitFlag=True then 
      begin
        exitflag:=false;
        exit;
      end;
    end; 
      

  4.   

      Application.ProcessMessages;for i:=1 to 5000 do
    begin
      windows.beep(300+i,500);
      if ExitFlag=True then 
      begin
        exitflag:=false;
        exit;
      end;
    end; 
      

  5.   

    我是想,
    显示一个提示窗口,当单击这个提示窗口的YES按钮时(如messagedlg) ,
    退出循环,
    如果不点击或按NO时,
    说明用户不在,
    则继续BEPP。
      

  6.   

    Application.ProcessMessages;for i:=1 to 5000 do
    begin
      windows.beep(300+i,500);
      if ExitFlag=True then 
      begin
        exitflag:=false;
        exit;
      end;
    end
    在onkeydown中
    if MessageDlg('是否终止循环?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
      begin
        ExitFlag := True;
      end;