Module Dftimer.pkg
************************************************************************
--- DFTimer Timer package for DataFlex programs
Copyright (c) 1983-2002 Data Access Corporation, Miami Florida,
All rights reserved.
DataFlex is a registered trademark of Data Access Corporation.
************************************************************************
Description:
This package contains all components needed to implement timers
in a DataFlex 4 program.
Author: Eddy Kleinjan, Data Access Nederland
************************************************************************
03/03/2001 EK Fixed Timer_Active_State to check for valid windows
handle before trying to set or kill a timer.
Fixed Kill_All_Timers to check for valid windows
handle before trying to kill a timer.
The windows handle might not exist anymore when the
program is being exited using Exit_Application.
12/13/2001 JJT fixed Timer_Active_State to check for -1 (not 0). Fixed a
a bug where set Timeout started inactive timers.
Added code to force timer object to desktop
************************************************************************
CLASS DFTimer
Usage:
Object MyTimer is a DFTimer
Set Timeout to 2000 // Default 1000
Set Auto_Start_State to TRUE|FALSE // Default TRUE
Set Auto_Stop_State to TRUE|FALSE // Default TRUE
Set Timer_Message to MyMessage // Default 0
Set Timer_Object to (MyObject(self)) // Default 0
Set Timer_Active_State to TRUE|FALSE // Default FALSE
// Augment when no Timer_Message
Procedure OnTimer
Send Info_Box "HEY, WAKE UP!"
End_Procedure
End_Object
DESCRIPTION
Objects of this class can be used to trigger an event after a
certain amount of time has passed. You can specify this time
by setting the Timeout property of the object. This timeout
is in miliseconds.
Whenever a timer event happens, it will notify the object by
sending an OnTimer event. You can trap this event to do whatever
you want the timer to do. By default this OnTimer event
will send the Timer_Message to Timer_Object, when these have
been specified.
By default, you have to activate a timer by setting its
Timer_Active_State to TRUE. When the timer has been placed
inside a user-interface object, it can also be activated
automatically when this user-interface object is being
activated. This only happes when it Auto_Start_State is TRUE,
which is the default setting. In such a case, the timer will
also automatically being stopped when the user-interface
object is taken of the screen. This depends on the
Auto_Stop_Timer state to happen.
When you need to set a new timeout value, you can do so
even when the timer is active. It will adjust the timeout
immediately.
Note that timer events depend on Windows for the delivery of
the event. Since timer events get a low priority in Windows,
it might put your program on hold when other programs are very
busy. In such a case, you will only receive one timer event
after the process stopped. There is no way, other than
calculating it yourself, to determine how many time has passed
or how many timer event should have happened since the last
timer event or timer activation.
PUBLIC INTERFACE
PROPERTIES
Auto_Start_State When TRUE (default) the timer will be activated
automatically when the object will be (virtually)
paged on the screen.
Example: When a timer object has been placed
inside a view, then the timer will be activated
when the view is activated.
Auto_Stop_State When TRUE (default) the timer will be deactivated
automatically when the object will be (virtually)
taken off the screen.
Timeout The timeout value for the timer to fire. The
timeout value must be set in miliseconds.
This property may be set even when the timer is
active. The new timeout value will be applied
immediately.
NOTE: The timeout set here is never precise. It
depends on Windows to deliver the message to our
application.
Default 1000.
Timer_Active_State
Set to TRUE to activate the timer, to FALSE to
deactivate the timer.
Timer_Message This property can be set to a messageID which has
to be sent whenever a timer event occurs. Default
this message will be send to the object itself
unless a Timer_Object as been specified.
Timer_Object This property can be set to an objectID which has
to receive the Timer_Message whenever a timer
event occurs. This value has no meaning when
no Timer_Message has been set.
METHODS
OnTimer This event will happen whenever the specified
amount of time has passed and the timer is
active. By default it sends the message in
the Timer_Message property to the object in
the Timer_Object when these have been specified.
When you don't need this, you can just override
the OnTimer event.
PUBLIC INTERFACE
Page_Object Has been augmented to auto_start the timer when
it becomes active as part or a user-interface
object.
Page_Delete Has been augmented to auto_stop the timer when
it is deactivated as part or a user-interface
object.
Destroy_Object Has been augmented to deactivate the timer.
Dftimer.pkg (view source)- import declarations
- Integer
SetTimer(Integer hWnd Integer idTimer Integer idTimeout Pointer tmprc)
- Integer
KillTimer(Integer hWnd Integer idTimer)
- Integer
giTimerManager - TimersArray : Array
This class is used to store the object IDs
of the active timer objects. It augments
the Destroy_Object procedure to notify
the DFTimerManager to kill all its active
timers.
NOTE: This class looks very much like the
Set class. I didn't want to use Set because
Remove_Element shifts items which I don't
want to happen because item numbers are used
as timerIDs.
- Integer
Find_Object(Integer iObj)
- Integer
iMax - Integer
iItem - Integer
iValue
- Integer
Add_Object(Integer iObj)
- Integer
iItem
Remove_Object(Integer iObj)
- Integer
iItem
Destroy_Object()
- DFTimerManager : DfBaseControl
This class is the actual timer manager
A timer will be created when Message Set_Timer_Active_State
has been send. This message needs two arguments. The first
is the objectID of the object to receive the timer event,
and the second is state. The object which ID has been passed,
needs to have a Timeout property to return the timeout for the
timer and it also needs to handle the MSG_OnTimer whenever a
timer event occurs.
The objectID of the Object will be placed in an array which contains
the objectIDs of all active timers. The Windows timer ID of a timer
is the itemnumber of the object in the array.
- DFTimerManagerPanel : dfBasePanel
This class acts as a container for the
timer manager object. This is needed because
A DFTimerManager object created directly at the
desktop doesn't have a Window_Handle which we
need to create a Windoows timer. By placing
this non-visual container around the timer
manager, it does get a Window_Handle.
The procedure End_Construct_Object has been
augmented to create a window and also
automatically page all children, which will
be the timer manager.
Construct_Object()
End_Construct_Object()
- DFTimer : Textbox
This is the class the user uses to create DFTimer objects
{ OverrideProperty=Skip_State DesignTime=False }
{ OverrideProperty=TypeFace DesignTime=False }
Construct_Object()
- Integer
Private.Timeout - Integer
Timer_Message - Integer
Timer_Object - Integer
Auto_Start_State - Integer
Auto_Stop_State
Set(Integer iState)
- Integer
iObj
- Integer
Timer_Active_State()
- Integer
iState - Integer
iObj
Set(Integer iTimeout)
- Integer
iActive
- Integer
Timeout()
- Integer
iTimeout
OnTimer(Integer iwParam Integer ilParam)
- Integer
iMsg - Integer
iObj
Page_Object(Integer iState)
Augmented to Auto_Start a timer
Page_Delete()
Augmented to Auto_Stop a timer
Destroy_Object()
Augmented to stop the timer
References (2):
Field References (0):
Module | Containing Symbol | Line |
---|