unit data_show;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
   
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }  re:integer;  end;var  Form1: TForm1;  count:integer;implementation{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);var    j:integer;
begin
    count:=111;
         re:=0;
        while count<1000 do
            begin
                    for j:=1 to 888 do
                       begin
                        label1.Caption:=inttostr(count+j);
                        label1.Refresh;
                        if re=1 then exit;
                        application.ProcessMessages;
                        end;                     if count=999 then
                        begin
                           count:=111;
                        end;            end ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  re:=1;
end;
end.请问如何 用回车键或者其他键代替button2的功能,我打算不采用button2,而是采用回车来实现对以上循环程序的暂停和启动,请问怎么解决。button1,可以用。谢谢

解决方案 »

  1.   

    是用回车代替Button2.OnClick吗?procedure TForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then re := 1;
    end;这样可以吗?
      

  2.   

    这样试试吧
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormActivate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        re:integer;
        procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
      end;var
      Form1: TForm1;
      count:integer;implementation{$R *.dfm}procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
    begin
      if Msg.message=WM_KEYUP then
        begin
          if Msg.wParam=VK_RETURN then
              re:=1;
        end;                 
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        j:integer;
    begin                    showmessage('aaaaaaaaaaaaaa');
        count:=111;
        re:=0;
        while count<1000 do
          begin
            for j:=1 to 888 do
              begin
                label1.Caption:=inttostr(count+j);
                label1.Refresh;
                application.ProcessMessages;
                if re=1 then
                  begin
                   exit;
                  end;
                end;
              if count=999 then
                begin
                  count:=111;
                end;
           end ;
    end;procedure TForm1.FormActivate(Sender: TObject);
    begin
      Application.OnMessage := MyMessageHandler;
    end;end.
      

  3.   

    procedure TForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then re := 1;
    end;
    用不用设置keypreview属性
      

  4.   

    我的那个循环是一直在进行的,所以
    procedure TForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then re := 1;
    end;
    这种形势是不能执行的,好像以上的程序是在程序结束的时候才得以实现的,有没有哥哥能继续告诉我的。多谢!!