CountDown Timer Demo

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Problem Description

This page describes a countdown timer class and provides a demonstration program illustrating it usage. 

 

Background & Techniques

A fan of our Akerue program recently wrote asking for some updates.  Akerue is a word search program written in Turbo Pascal and released many years ago by Borland as part of a games package.   One of the features not yet implemented is the time limit on user searches.  I rarely get more than 10 or 20% of the possible words anyway, so the time limit feature didn't seem important, but Adrian says she needs it just to reduce the number of hours she spends searching for those last few words!    In any event, I could not find a good, free Delphi countdown timer so I wrote this one.

TCountDown is a new class derived from TPanel  which uses a TPanel as a prototype at create time displays.   This is my alternative to user installed visual components.   I keep losing them with every new CPU, operating system, or Delphi version upgrade, at least one one of which occurs annually.    This method allows one to visually drop the prototype component on the form and define its characteristics and still be assured that the program will compile successfully next year.      

TCountDown has a digital or analog clock display with a number of features, the essential ones being methods to set the time, start the timer, and pause the timer.   An OnExpired event exit can notify the program when the timer reaches zero.   A new (February 2016) feature is an OmTimerPop event exit which allows the programmer to gain access every time the 1 second time timer pops.  

The best way to learn the usage details is to study the code.  here are a few  notes about features which might not be obvious:

  1. A TPanel is passed to the create constructor as a prototype for the timer.  Location, size, font, etc. are inherited from the prototype. This allows us many of the visual development advantages without the hassles involved with installed user components.
  2. If an analog clock timer type is used (analogClock := true), the prototype panel height is compared to its width. If height exceeds width by enough to display the timer in at least 6 point type, the times will be displayed in digital as well as analog form.
  3. An OnExpired notify event exit is available to tell the user when time has counted down to 0. By default, the OnExit event of the prototype is used as the OnExpired event.
  4. The "click" sound effect is loaded as a memory resource at create time.  ClickSound.res included with the source download is created from wave file Click2.wav by the resource compiler called by Genres.bat and as defined by Clicksound.rc all included in the source file but only ClickSound.res is required to recompile  unless you wanted to substitute your a own preferred click sound.   

  Addendum June 21, 2006:   I recently wanted to use the timer to display run time for a long running program.   Version 2 adds a feature to allow the timer to run up or down so it can be used for this purpose. The CPU intensive program being timed, also uncovered a problem with the original timer - it ran slow because on the timer code could not always execute at one second intervals.  The new version displays the time since the the timer was started rather than counting on 1 second timer updates. 

February 21, 2016:  Version 2.1 of the demo program tests the new OnTimerPop event exit in TCountDown by "beeping" the speaker for each change in the Minute of the displayed digital time value (i.e. beep each time the displayed Second value is 0).  

Running/Exploring the Program 

Suggestions for Further Explorations

???

 

Original Date: May 7, 2006 

Modified: February 21, 2016

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.