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

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

问题描述

是否可以确定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.

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

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