timerControl.cl
Code: Select all
class timerControl
open core
predicates
startTimer : (window).
stopTimer : ().
end class timerControl
Code: Select all
implement timerControl
open core
class facts
myTimer : vpiDomains::timerId := erroneous.
clauses
startTimer(Win) :-
myTimer := vpi::timerSet(Win:getVpiWindow(), 1000), % Need to get the handle for the window parameter
stdio::write("Timer set for 1 sec.\n").
stopTimer() :-
vpi::timerKill(myTimer),
stdio::write("Timer stopped.\n").
end implement timerControl
Code: Select all
predicates
onMouseDown : window::mouseDownListener.
clauses
onMouseDown(Source, _Point, _ShiftControlAlt, _Button) :-
timerControl::startTimer(Source). % Call to start the timer for window Source
predicates
onStartTimerClick : button::clickResponder. % Start Button clicked
clauses
onStartTimerClick(Source) = button::defaultAction :-
timerControl::startTimer(Source). % Call to start the timer for button Source
predicates
onStopTimerClick : button::clickResponder. % Stop Button clicked
clauses
onStopTimerClick(_Source) = button::defaultAction :-
timerControl::stopTimer. %Call to stop the timer
predicates
onStartTimerTimer : window::timerListener. % Timer for Start Button event fired
clauses
onStartTimerTimer(_Source, _Timer) :-
stdio::write("Timer event from Button\n").
predicates
onTimer : window::timerListener. % Timer for the Form event fired
clauses
onTimer(_Source, _Timer) :-
stdio::write("Timer event from Form\n").
Result: When initiating the timer using either method the ‘Timer set…’ text is displayed in the Messages window. When clicking the stopTimer_ctl button, the ‘Timer stopped’ text is displayed in the Messages window. It also appears that all variables are being properly set (as viewed in the Debug mode).
The problem is that the timer event for both the form and button are not firing so the ‘Timer event…’ text is not being displayed.
I suspect that the problem may be with the vpi::timerSet call. Examples from web site show a ‘window’ parameter being passed to vpi::timerSet. When I did this, I get a compile time error since vpi::timerSet in looking for a ‘windowHandle’ as the parameter not a ‘window’. So I added ‘getVpiWindow’ to the parameter to get the handle of the window object being passed. Currently, I’m using the personal version of Visual Prolog 9 Build 906.
Any help or suggestions would be greatly appreciated. Thanks.