ros*_*mcm 3 delphi event-handling taction delphi-2006 python-idle
我的D2006应用程序中有一个OnIdle处理程序.使用此代码:
procedure TMainForm.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
begin
Inc (IdleCalls) ;
Sleep (10) ;
Done := False ;
end ;
Run Code Online (Sandbox Code Playgroud)
应用程序运行平稳,空闲处理程序每秒调用100次,CPU使用率接近于零.
然后我添加了一个TActionList并将一些控件连接到操作,编写了一个Execute和Update处理程序.
procedure TMainForm.ActionNewButtonExecute(Sender: TObject);
begin
DoNewProject ;
end ;
procedure TMainForm.ActionNewButtonUpdate(Sender: TObject);
begin
ActionNewButton.Enabled := AccessLevelIsSupervisor ;
end;
Run Code Online (Sandbox Code Playgroud)
问题.OnUpdate事件不会触发.在预感中,我在OnIdle处理程序中设置了Done:= true,然后只有在我移动鼠标时才会调用OnIdle处理程序.并且更新操作仍然不会触发.
为什么更新处理程序可能不会被触发,我应该将Done设置为true还是false?或两者?
使用来源,卢克.:)
Forms具体来说,请看单位TApplication.Idle.它部分包含以下内容:
Done := True;
try
if Assigned(FOnIdle) then FOnIdle(Self, Done);
if Done then
if FActionUpdateDelay <= 0 then
DoActionIdle
// Excluded to avoid copyright violation
// See also the else portion, which contains (in part)
else
if IdleTimerHandle = 0 then
begin
IdleTimerHandle := SetTimer(0, 0, FActionUpdateDelay, IdleTimerDelegate);
if IdleTimerHandle = 0 then
DoActionIdle
end;
finally
// Omitted
end;
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,DoActionIdle只有所谓的当任Done = True and FActionUpdateDelay <= 0或IdleTimerHandle = 0.DoActionIdle(也是TApplication的一部分)是什么叫UpdateAction.因此,如果上述条件都不满足,则永远不会调用TAction.OnUpdate.
还有一个单独的方法,TApplication.DoMouseIdle您可能也想要仔细阅读.
| 归档时间: |
|
| 查看次数: |
2555 次 |
| 最近记录: |