gpt4 book ai didi

Delphi 空闲处理程序仅在我移动鼠标时触发

转载 作者:行者123 更新时间:2023-12-03 15:41:15 25 4
gpt4 key购买 nike

我的 D2006 应用程序中有一个 OnIdle 处理程序。使用此代码:

procedure TMainForm.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);

begin
Inc (IdleCalls) ;
Sleep (10) ;
Done := False ;
end ;

应用程序运行平稳,空闲处理程序每​​秒调用 100 次,CPU 使用率接近于零。

然后,我添加了一个 TActionList 并将一些控件连接到操作,编写了一个执行和更新处理程序。

procedure TMainForm.ActionNewButtonExecute(Sender: TObject);
begin
DoNewProject ;
end ;

procedure TMainForm.ActionNewButtonUpdate(Sender: TObject);
begin
ActionNewButton.Enabled := AccessLevelIsSupervisor ;
end;

问题。 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;

如您所见,DoActionIdle仅当 Done = True and FActionUpdateDelay <= 0 时才被调用或IdleTimerHandle = 0DoActionIdle (也是 TApplication 的一部分)称为 UpdateAction 。因此,如果上述两个条件都不满足,则永远不会调用 TAction.OnUpdate。

有一个单独的方法,TApplication.DoMouseIdle ,您可能也想仔细阅读。

关于Delphi 空闲处理程序仅在我移动鼠标时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5507502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com