请问各位大侠,如何在for循环中响应系统事件,如鼠标事件(100分)

  • 主题发起人 主题发起人 lsa_78
  • 开始时间 开始时间
L

lsa_78

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位大侠,如何在for循环中响应系统事件,如鼠标事件
 
for I := 0 to n do
Begin
....
application.processmessage;
...
end;
 
对,用application.processmessage;
没有错了。
 
能不能举一个具体的例子,如判断有没有按下Esc键?
 
搞不懂了~~~
有没有按下ESC和FOR有什么关系?是在OnKeyDown里判断的。
 
事件触发你就知道了,循环干什么呀?
 
>>事件触发你就知道了,循环干什么呀?
同意,用循环思路就不对!严重影响速度
 
不明白楼主要干什么?
好象是
while true do
begin
if message=someMessage then
...
end;

没必要这么做啊?!
 
感谢各位高手,现在我想把我的意图各位讲明白一下:
我在循环执行一个动作的时候,由于则个循环执行起来,比较废时间,我想在中间按下
Esc键,结束循环,请各位不吝赐教!谢谢!
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
InWorking: Boolean;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
if InWorking then
begin
InWorking := False;
Exit;
end;
InWorking := True;
for i:=1 to 5 do
begin
showmessage(inttostr(i));
repeat
Application.ProcessMessages;
until not InWorking;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
InWorking:=False;
self.close;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
showmessage(key);
end;

procedure TForm1.Button1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=27 then
begin
InWorking:=False;
end;
end;

end.
 
事件触发中改一个标志,循环中判标志
 
后退
顶部