This object is a more accurate instrument for counting time intervals than a simple timer. It uses the so-called "multimedia" timer, which does not require a window handle for its operation, and instead of sending messages, it directly calls the custom handler. Moreover, the call always takes place in someone else's (system) command stream. Those. not only is it not guaranteed that the event will only fire when the process is waiting for messages, but on the contrary: it will almost certainly interrupt the current operation in order to execute the specified handler.
Hierarchically, TMMTimer does not derive from TObj, but inherits from TTimer. The SetEnabled method of the TObj object is virtual, therefore, in principle, you can pass the TMMTimer object as a parameter of some procedures instead of TTimer.
Multimedia Timer Constructor:
NewMMTimer(i)- returns a pointer of the PMMTimer type. As an interval, you can specify values less than 50 milliseconds (including the minimum possible value of 1 millisecond). But the accuracy of this timer, although higher, still cannot be limitless. The Windows operating system is not a real-time system. Even the observance of the declared accuracy for this kind of timer (10 milliseconds by default) is not guaranteed if the system suddenly thought that it had more important things to do. To improve accuracy, you can specify a higher resolution (i.e. lower the Resolution property), raise the priority of your task, or stop using Windows (just kidding).
Properties, methods, event for TMMTimer are the same as those of its ancestor in the TTimer hierarchy. Two more properties are added:
Periodic - the timer is periodic (by default, this property contains true immediately after the object is created, i.e. the timer is created periodic). The non-periodic timer differs in that when triggered, it automatically goes into an inactive state, i.e. it is "disposable";
Resolution - the accuracy of the multimedia timer. A value of 0 (which is used by default) means absolute accuracy, but leads to a complete degradation of system performance. Those. the system can no longer do anything, in this case it only counts the time, and the task manager, if it can work, will only show that the processor is 100% loaded. A value of 10 is generally an acceptable value and it is recommended not to use lower values whenever possible.
In the general MCK mirror for simple and multimedia timers, TKOLTimer, specifically for setting up a multimedia timer, there are Periodic and Resolution properties. The design-time property Multimedia should be used to switch the timer from normal to multimedia and back again.
And please don't forget that the media timer handler is called on its own command flow, i.e. it is necessary to ensure the protection of resources and parts of the code that are not "re-entrant" (reentrant is an old designation, which even managed to firmly enter the technical language before the advocates of the purity of Russian speech realized themselves). In particular, it is undesirable to work with window objects, except by sending messages to them by en-queuing messages (TControl.Postmsg method, or PostMessage API function). See also the next chapter (TThread object) for more details on securing code sections.