Delphi Timer:下一个事件之前的时间 [英] Delphi Timer: Time before next event

查看:26
本文介绍了Delphi Timer:下一个事件之前的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定 Delphi 中的 TTimer 何时触发?我知道如何根据计时器的上次运行和计时器间隔来计算它.不幸的是,我正在使用的代码有很多状态,并且间隔可以以多种方式改变.我宁愿不必跟踪上次启用计时器和更改间隔的时间,而是直接从计时器访问此信息.

Is it possible to determine when a TTimer in Delphi will trigger? I know how to calculate this based upon the timer's last run and the timers interval. Unfortunately, the code I am working with has many states and the interval can change in many ways. I would prefer to not have to keep track of when the timer was last enabled and the interval changed, but instead directly access this information from the timer.

场景:一个计时器有 2 分钟的间隔,自上次启用以来已经过去了 30 秒,我如何在代码中找出 90 秒后计时器事件将再次触发?

Scenario: A timer has a 2 minute interval, 30 seconds have elapsed since it was last enabled, how do I find out in code that in 90 seconds the timer event will trigger again?

是否可以直接从计时器中获取此信息?或者也许是操作系统?计时器组件必须知道"下次触发的时间.它怎么知道?我可以访问这些信息吗?

Is it possible to get this information from the timer directly? Or perhaps the OS? The timer component must "know" when it will be triggered next. How does it know? Is this information I can access?

推荐答案

绝对没有办法查询 Windows 计时器以获取这种性质的信息.您只需要自己跟踪即可.

There's absolutely no way to query a Windows timer for information of this nature. You will simply have to keep track of this yourself.

我会通过用组合而不是继承来包装 TTimer 来做到这一点.然后,您可以确保您将捕获对计时器状态的所有修改.

I would do this by wrapping up the TTimer with composition and not inheritance. You can then be sure that you will capture all modifications to the timer state.

这篇关于Delphi Timer:下一个事件之前的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆