希望能够做到 让程序暂时停止,等button1被按下后才继续运行!请问如何实现?

解决方案 »

  1.   

    这要看你是什么程序
    如果是循环之类的可以用这种方法程序加上一个全局boolean变量IfStop
    在循环体开始的地方加上一句判断如果IfStop=True
    那么记下现在的循环状态 然后退出
    button1被按下后IfStop := False
    再重新开始循环 继续原来的状态如果是一般有程序可能可以通过系统达到目的 但我不会
      

  2.   

    不知要怎么样理解,暂停是否禁止窗口获得一切消息呢
    如果是的话,用载获消息的方法,如下面的代码:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure AppMessage(var Msg: TMsg; var Handled: Boolean);  end;var
      Form1: TForm1;
      iscon:boolean;//全局变量,决定窗口是否暂停,False为暂停。
    implementation{$R *.dfm}procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
    begin
      //如果消息是鼠弹起的消息,并且窗口句柄是Button1,
       则设isCon为相反,此时如果iscon为True,则点下后变成False,窗口“暂停”
       相反则IsCon变为True,窗口开始运行。
      if (Msg.message =WM_LBUTTONUP)and(Msg.hwnd=Button1.Handle) then
      begin
        iscon:=not iscon;
        Handled := False;
        exit;
      end;
      if iscon then
        Handled:=False
      else
        Handled:=True;
    end;
    //点下Button2,开始截获一切消息并在AppMessage中判断。
    procedure TForm1.Button2Click(Sender: TObject);
    begin
       Application.OnMessage:=AppMessage;
    end;end.