Delphi-timer usage

Source: Internet
Author: User

The timer is a non-visual component that can trigger ontimer events on a regular basis to complete analog clock, system latency, countdown, and other work. In the system tab.
1. main attributes of Timer
(1) enabled attribute: When the value is true, enable the timer; otherwise, disable the timer. The default value is true.
(2) interval attribute: controls the interval of ontimer event triggering, in milliseconds. Setting interval to 0 is equivalent to disabling the timer. Default Value: 1000 ms (1 second ).
2. Major timer events
Timer only has one ontimer event. When timer is enabled, Timer triggers the ontimer event and runs the program at the time specified by the interval attribute.
Example: Countdown
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, spin, extctrls, stdctrls, mask, buttons;
Type
Tform1 = Class (tform)
Timer1: ttimer;
Maskedit1: tmaskedit;
Bitbtn1: tbitbtn;
Procedure timer1timer (Sender: tobject );
Procedure formcreate (Sender: tobject );
Procedure bitbtn1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
M, S: integer;
Implementation
{$ R *. DFM}
Procedure tform1.timer1timer (Sender: tobject );
Begin
S: = s-1;
If S =-1 then
Begin
S: = 59;
M: m-1;
If M =-1 then M: = 59;
End;
Maskedit1.text: = inttostr (m) +':'+ Inttostr (s );
Maskedit1.sellength: = 0;
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
M: = 9; S: = 10; // initial time: 09: 10 seconds
Maskedit1.editmask: ='! 00: 00; 1; 0'; // Time format, 0 for non-input characters
Timer1.interval: = 1000;
End;

Procedure tform1.bitbtn1click (Sender: tobject );
Begin
Timer1.enabled: = Not timer1.enabled; // stop countdown
End;
End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.