Correct way to stop a script

I am having problems stopping a script from within my program.
If I use:
if (pPs.Running) then pPs.stop;

The finally of my try… finally never gets called? Should it?
Therefore, I am unable to free the form and associated controls.
I tried posting an event to the script, having the script exit internally.
But, I am having difficulty in that as well?
So, what is the best way to stop a script that is executing that will allow
the try finally to process?

Ken Davis

Introduce a boolean api to the script, say Stop: Boolean, and make that return true whne it has to stop. From your code check it occasionally.