If a prolog program is exited the virtual machine program must also stop, this can be done by responding to the onClose event of the main window of a prolog program and with the built-in predicate prolog_vm/0. The predicate prolog_vm/0 is exited successfully if the prolog program is being executed by the virtual machine program, if the prolog program is being interpreted by the Trinc-Prolog development environment or the DLL version it fails.
| testFrame::doOnClose( X ) :- prolog_vm, %Succeeds if virtual machine is executing program, else fails app<-startQuit. %Stop program |
The example above shows an event handler for the onClose event that stops the Virtual Machine application if it is being run by the Virtual Machine program and else not.
As of release 3 of the Trinc-Prolog there is the predicate stop_vm/0, this predicate succeeds if the virtual machine program is executing the prolog program and the side-effect of the predicate is that it starts the quitting process of the virtual machine application. The example above can be rewritten to:
| testFrame::doOnClose( X ) :- stop_vm. %Stops virtual machine if it is executing the prolog program |