unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm} var Add:boolean=false; procedure TForm1.Button1Click(Sender: TObject); begin Add:=not Add; while add do begin application.ProcessMessages; sleep(50); edit1.Text:=inttostr(strtoint(edit1.Text)+1); end; end;procedure TForm1.FormCreate(Sender: TObject); begin edit1.Text:='0'; end;end.
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if Edit1.Text = '' then Edit1.Text := '0'; Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1); Sleep(20); Application.rocessMessages;
end;
用一个timer 控件不就行了吗!
在TForm的OnKeyDonw事件里写代码
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin IsAdd:=not IsAdd; //布尔型全局变量初始值置False while add do begin application.ProcessMessages; sleep(50); label1.Caption:=inttostr(strtoint(label1.Caption)+1); end; end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
var
Add:boolean=false;
procedure TForm1.Button1Click(Sender: TObject);
begin
Add:=not Add;
while add do
begin
application.ProcessMessages;
sleep(50);
edit1.Text:=inttostr(strtoint(edit1.Text)+1);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text:='0';
end;end.
begin
if Edit1.Text = '' then Edit1.Text := '0';
Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1);
Sleep(20);
Application.rocessMessages;
end;
Shift: TShiftState);
begin
IsAdd:=not IsAdd; //布尔型全局变量初始值置False
while add do
begin
application.ProcessMessages;
sleep(50);
label1.Caption:=inttostr(strtoint(label1.Caption)+1);
end;
end;
sleep(50);