class Timer : Compteur




Objet qui permet d'exécuter une fonction au bout du temps défini.

L'objet Timer doit être désactivé et effacé à la fermeture de la forme qui l'a ouvert.


Exemple : une horloge simple.


* ClassTimer.wfm - Exemple de la classe Timer.
* --------------------------------------------
*
PRIVATE F
*
F = new ClassTimerForm()
F.open()
*
* ------------------------------------------------------------------------------
CLASS ClassTimerForm of FORM
* ------------------------------------------------------------------------------
*
with (this)
 mdi = .F.
 onOpen  := class::Form_OnOpen
 onClose := class::Form_OnClose
 height  := 5
 left    := 50
 top     := 10
 width   := 50
 text    := "Exemple classe Timer"
endwith
*
this.TEXT1 = new TEXT(this)
 with (this.TEXT1)
  height    := 5
  left      := 0
  top       := 0
  width     := 50
  fontSize  := 64
  alignment := 4
  text      := TIME()
 endwith
*
* ------------------------------------------------------------------------------
FUNCTION Form_OnClose
* ------------------------------------------------------------------------------
*
* "this" désigne form
*
this.TIMER1.enabled  := .F.
RELEASE OBJECT this.TIMER1
*
RETURN null
*
* ------------------------------------------------------------------------------
FUNCTION Form_OnOpen
* ------------------------------------------------------------------------------
*
* "this" désigne form
*
this.TIMER1 = new Timer()
this.TIMER1.parent = this                      && Intégrer TIMER1 dans la forme.
this.TIMER1.onTimer  := class::TIMER1_OnTimer
this.TIMER1.interval := 1
this.TIMER1.enabled  := .T.
*
RETURN null
*
* ------------------------------------------------------------------------------
FUNCTION TIMER1_OnTimer
* ------------------------------------------------------------------------------
*
* "this" désigne form.TIMER1
*
this.parent.TEXT1.text := TIME()
*
RETURN null
*
ENDCLASS


Fiche fabriquée le : 21/05/11 à 07:57:20