FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

SYSTEM

Handle events


I think your code will have to _decide_ what events it wants to process. This sort of thing was discussed at great length in the "Break...Until" thread some time ago.

A sample code of what _I_ do is at the end of this email.

The main loop is:

DO
  HANDLEEVENTS
  FN myHandleevents
UNTIL theWorldEnds

This grabs the events in HANDLEEVENTS, leaps to an event "parser" (FN myHandleevents), which sets a global variable to indicate the state of that particular event. Then FN myHandleevents calls another function (FN processMyHandleevents) which looks at the global variables and decides what to do with them.

I do it this way because I want to see the event, but don't particulary want to get stuck inside HANDLEEVENTS. This may seem like double handling to some, but indirection is the name of my game. I use HANDLEEVENTS to detect the event, not to process the event.

Code example follows:

'_________________________________________________
'This code waits for 2 sec then beeps continuously.
'Break and a mouse click are detected and end the program.
'Compile and run this program, otherwise you may become
'confused about what is actually happening. (The FB run
'environment continues to beep after you have done a
'break or a mouse click, the compiled code doesn't.)

COMPILE 0, _dimmedVarsOnly
WINDOW 1

'_________________________________________________
'Globals
GLOBALS
DIM theWorldEnds
DIM yes
DIM no
DIM timerEvent
DIM breakEvent
DIM mouseEvent
DIM beeperOn
END GLOBALS

'_________________________________________________
'Constants
theWorldEnds=0
yes=1
no=0
timerEvent=no
breakEvent=no
mouseEvent=no
beeperOn=no

'_________________________________________________
LOCAL FN beeper
  BEEP
END FN

'_________________________________________________
LOCAL FN processMyHandleevents

  SELECT beeperOn
    CASE yes
      FN beeper
  END SELECT

END FN

'_________________________________________________
LOCAL FN myHandleevents

  SELECT breakEvent
    CASE yes
      theWorldEnds=yes
  END SELECT

  SELECT mouseEvent
    CASE yes
     theWorldEnds=yes
  END SELECT

  SELECT timerEvent
    CASE yes
      beeperOn=yes
  END SELECT

  FN processMyHandleevents

END FN

'_________________________________________________
'Changes the value of a global variable based upon what
'HANDLEVENTS has found in the event queue.

LOCAL FN doBreak
  breakEvent=yes
END FN

LOCAL FN doTimer
  timerEvent=yes
END FN

LOCAL FN doMouse
  mouseEvent=yes
END FN

'_________________________________________________
'main program

ON BREAK FN doBreak
ON TIMER(2) FN doTimer
ON MOUSE FN doMouse

DO
  HANDLEEVENTS
  FN myHandleevents
UNTIL theWorldEnds

END

Peter