是不是没用application.ProcessMessages ?unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Edit2: TEdit; procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var i:integer; begin if key=13 then begin for i:=1 to 100000 do begin edit2.Text := inttostr(i); application.ProcessMessages ;//试试不加这句的效果 end; end; end;end.
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var msg: MSG; begin if Key=VK_RETURN then begin ShowMessage('enter'); if PeekMessage(@msg,nil,nil,nil,PM_REMOVE) then begin TranslateMessage(@msg); DispatchMessage(@msg); end; end; end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i:integer;
begin
if key=13 then
begin
for i:=1 to 100000 do
begin
edit2.Text := inttostr(i);
application.ProcessMessages ;//试试不加这句的效果
end;
end;
end;end.
Shift: TShiftState);
var
msg: MSG;
begin
if Key=VK_RETURN then
begin
ShowMessage('enter');
if PeekMessage(@msg,nil,nil,nil,PM_REMOVE) then
begin
TranslateMessage(@msg);
DispatchMessage(@msg);
end;
end;
end;
GetCursorPos(APoint);//APoint:TPoint
SetCursorPos(APoint.x,APoint.y);
建议参见DELPHI消息处理