class Timer example
Suppose you want to display the date and time in a form. The following is an onOpen event handler that creates a Timer object and attaches it to the form. A reference to the form is added to the Timer object so that the timer’s onTimer event handler can update the form. Another method in the form is assigned as the Timer object’s onTimer event handler. The time is updated every two seconds instead of every second, so that dBASE Plus is not too bogged down constantly updating the time.
function Form_onOpen()
this.timer = new Timer( ) // Make timer a property of the form
this.timer.parent = this // Assign form as timer's parent
this.timer.onTimer = this.updateClock // Assign method in form to timer
this.timer.interval = 2 // Fire timer every 2 seconds
this.timer.enabled = true // Activate timer
The following is the updateClock( ) method of the form, assigned as the onTimer event handler. Because the Timer object calls this method, the this reference refers to the Timer object, not the form, even though the method is a method of the form. A reference to the form has been stored in the parent property of the timer; an Text component of the form named clock is updated through that reference.
function updateClock()
this.parent.clock.text = new Date()
The timer should be deactivated when the form is closed. Use the form’s onClose event:
function Form_onClose()
this.timer.enabled = false