Skip to content

Class: DFTimer

Properties | Events | Methods | Index of Classes

Enabled DFTimer objects can be used to trigger an event after a certain amount of time has passed.

Hierarchy

cObject > cUIObject > DfBaseObject > DfBaseWindow > DfBaseUIWindow > DfBaseControl > DfBaseTextbox > TextBox > DFTimer

Show full hierarchy and direct subclasses

Library: Windows Application Class Library

Package: Dftimer.pkg

Description

This class is obsolete. It has been replaced by:

Constant Meaning
cTimer Used to trigger an event after a certain amount of time has passed
cIdleHandler Used to create objects that generate events on a periodic basis
cWebTimer Timer for web applications

DFTimer objects can be used to trigger an event after a certain amount of time has passed.

Sample

Use Windows.pkg
Use DFTimer.pkg

Object oTestPanel is a BasicPanel 
    Set Label to "Timer Test Panel"
    Set Size to 162 178
    Set Minimize_Icon to FALSE
    Set Maximize_Icon to FALSE
    Set Border_Style to Border_Dialog

    Property Integer piUserTimeout 1000

    Set Locate_Mode to Center_on_Screen

    Object oBorder1 is a Container3d
        Set Size to 114 162
        Set Location to 7 6

        Object oGroup1 is a Group
            Set Label to "Explanation"
            Set Size to 56 151
            Set Location to 9 4

            Object TextBox1 is a TextBox
                Set Label to "This sample program triggers a timer event"
                Set Location to 12 6
            End_Object    // TextBox1

            Object TextBox2 is a TextBox
                Set Label to "whenever 'Timeout' milliseconds have "
                Set Location to 21 6
            End_Object    // TextBox2

            Object TextBox3 is a TextBox
                Set Label to "passed. You can change the time out value"
                Set Location to 30 6
            End_Object    // TextBox3

            Object TextBox4 is a TextBox
                Set Label to "dynamically. Timer has been 'Auto_Started'."
                Set Location to 39 6
            End_Object    // TextBox4

        End_Object  // oGroup1

        Object oTimeoutForm is a Form
            Set Label to "Timeout value"
            Set Label_Col_Offset to 4
            Set Label_Justification_Mode to jMode_Right
            Set Size to 13 51
            Set Location to 73 56
            Set Value to (piUserTimeout(self))

            Procedure OnKillFocus
                Integer iTimeOut

                Get Value to iTimeOut
                Set piUserTimeout to iTimeOut // will delegate
            End_Procedure

            // This procedure will be called by the timer object
            // whenever a timout occurs.
            Procedure Increment_Counter
                Integer iValue

                Get Value to iValue
                Increment iValue
                Set Value to iValue
            End_Procedure

        End_Object    // Timeout

        Object oEventCount is a Form 
            Set Label to "Event fired"
            Set Label_Col_Offset to 4
            Set Label_Justification_Mode to jMode_Right
            Set Size to 13 51
            Set Location to 90 56
            Set Enabled_State to False

            // This procedure will be called by the timer object
            // whenever a time out occurs.
            Procedure Increment_Counter
                Integer iValue

                Get Value to iValue
                Increment iValue
                Set Value to iValue
            End_Procedure

        End_Object    // oEventCount

        Object TextBox1 is a TextBox
            Set Label to "milliseconds"
            Set Location to 74 112
        End_Object    // TextBox1

        Object TextBox2 is a TextBox
            Set Label to "times"
            Set Location to 92 112
        End_Object    // TextBox2

    End_Object    // oBorder1

    Object oStartButton is a Button
        Set Label to 'Start Timer'
        Set Location to 127 6
        Procedure OnClick
           Send Start_Timer
        End_Procedure // OnClick
    End_Object    // oStartButton

    Object oStopButton is a Button
        Set Label to 'Stop Timer'
        Set Location to 127 62
        Procedure OnClick
           Send Stop_Timer
        End_Procedure // OnClick
    End_Object    // oStopButton

    Object oCancelButton is a Button
        Set Label to 'Close'
        Set Location to 127 118
        Procedure OnClick
           Send Exit_Application
        End_Procedure // OnClick
    End_Object    // oCancelButton

    // This is the actual timer object.
    Object oTimer is a DFTimer
        // Things you might set:
        //   Set Timeout to 2000
        //   Set Auto_Start_State to TRUE|FALSE 
        //   Set Auto_Stop_State to TRUE|FALSE 
        //   Set Timer_Message to MyMessage
        //   Set Timer_Object to oMyObject
        //   Set Timer_Active_State to TRUE|FALSE 
        Procedure OnTimer
            Send Increment_Counter of ;
                (oEventCount(oBorder1))
            // Or whatever you like!
        End_Procedure
        // The same as above can be accomplished by this:
        //    Set Timer_Message to Increment_Counter
        //    Set Timer_Object  of (oEventCount(oDialog1))
    End_Object  // oTimer

    Procedure Start_Timer
        Set Timeout of oTimer to (piUserTimeout(Self))
        Set Timer_Active_State of oTimer to True
    End_Procedure

    Procedure Stop_Timer
        Set Timer_Active_State of oTimer to False
    End_Procedure
End_Object    // oTestPanel

Send Activate of oTestPanel
Start_UI

Syntax

Object oMyTimer is a DFTimer
    Set TimeOut to 2000                // Default 1000
    Set Auto_Start_State to TRUE| FALSE
    Set Auto_Stop_State to TRUE| FALSE
    Set Timer_Message to MyMessage
    Set Timer_Object to oMyObject
    Set Timer_Active_State to TRUE|FALSE

    // Define when no Timer_Message
    Procedure OnTimer
        Send Info_Box "text"
    End_Procedure
End_Object

Of Special Note

Objects of this class can be used to trigger an event every time a certain amount of time has passed since the last event or the timer was activated. You can specify this time interval by setting the timeout property of the object. This value is stated in milliseconds, but the effective resolution of events is about 55 milliseconds, so there would be little point in specifying intervals more-precisely than this.

At the prescribed interval, the timer will send an onTimer event. You can trap this event to do whatever you want. By default, this onTimer event will send the timer_message to the timer_object, when both of these exist and have been specified.

A timer is activated by setting its timer_active_state true. When the timer has been placed inside a user-interface object, it will be activated automatically when the user-interface object is activated. This is governed by the auto_start_state property, which is true by default. The timer will automatically stop when the user-interface object is deactivated. This is governed by the auto_stop_state property, which is also true by default.

When you wish to set a new timeout interval, 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, Windows may stop the timer process when other programs are very busy. When this happens, the timer will stop until the process is resumed. There is no way, other than calculating it yourself, to determine how much time passed or how many timer events should have happened between the last timer event before the process was stopped and the first event after the process is resumed.

See Also

Info_Box