Cicode Programming Reference > Performing Advanced Tasks > Handling Events

Handling Events

Cicode supports event handling. You can define a function that is called only when a particular event occurs. Event handling reduces the overhead that is required when event trapping is executed by using a loop. The following example illustrates the use of the OnEvent() function:

INT 
FUNCTION MouseCallback()
INT x, y;
DspGetMouse(x,y);
Prompt("Mouse at "+x:####+","+y:####);
RETURN 0;
END
OnEvent(0,MouseCallback);

The function MouseCallBack is called when the mouse is moved - there is no need to poll the mouse to check if it has moved. CitectSCADA watches for an event with the OnEvent() function.

Because these functions are called each time the event occurs, you should avoid complex or time consuming statements within the function. If the function is executing when another call is made, the function can be blocked, and some valuable information may be lost. If you do wish to write complex event handling functions, you should use the queue handling functions provided with Cicode.

See Also

Performing Advanced Tasks