timerListener not firing
Posted: 24 Aug 2020 1:36
Hope someone can help me understand and get the timerListener event to fire. I’ve created a very simple project which has one form, ‘timerTest’. This form has just 2 buttons; 1) startTimer_ctl, and 2) stopTimer_ctl. In addition, there is a class, ‘timerControl’ that contains two clauses; 2) startTimer, and 2) stopTimer. The project contains the following code:
timerControl.cl
timerControl.pro
timerTest.pro (only the relevant clauses)
As can be seen, I have two ways to start the timer; 1) onMouseDown on the form, and 2) clicking the startTimer_ctl button. You can also see that the onTimer event has been defined for both the form and start button.
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.
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.