Article ID:qGEN001
Date Revised:October 17, 1997
Keywords:ON SHUTDOWN, READ EVENTS, CLEAR EVENTS, QueryUnload(), Application
See Also:KB Article Q110970 

Question: Why do I get the message "Cannot Close FoxPro" when trying to close the FoxPro or my application window?

Answer: Usually it is because you have a READ EVENTS holding VFP in it's event processing loop.

Given a simple application that launches one main form that might spawn other modeless child forms. Here's one way to close all the active forms:

on shutdown do CloseForms

do form XYZ
read events  && the form will now "have control of the app"

on shutdown
return


procedure CloseForms
local i

for i = _screen.FormCount to 1 step -1
   if ( _screen.Forms[i].QueryUnload() )
      _screen.Forms[i].Release()
   endif
endfor

return

Each form will have its QueryUnload() method called which if it returns .T. then the form Release(), Destroy() and Unload() methods will execute. At some point you must issue a CLEAR EVENTS to terminate the event processing loop. I do this in the XYZ form Unload() method so that when the main form is closed the whole app shuts down.

Note: If you just click the form window X (close) button the Release() method is not called.

The QueryUnload() method would be the point at which you can determine if the app can be shutdown, carry out the necessary TABLEUPDATE() and/or TABLEREVERT() commands.


1