Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Shutdown (no if's and but's)
Message
 
To
24/05/2002 06:45:51
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00660933
Message ID:
00660986
Views:
9
Hello Kevin

faqs section by "Nadya Nosonovsky"
Frequently Asked Questions

Title

How can I release all open forms

Summary

This entry is based on the following thread: Coding, syntax & commands Re: Program to close all forms Thread #359746. In order to release all open forms you need to do it backwards through the collection. If the forms use the QueryUnload method to check to make sure the form can release, you'd need to check the results of that as well.

Description

See more info about it at WiKi



********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: George Tasker
* Modified by.......:
********************************************************************
local lnForms, llDone
lnForms = _SCREEN.FormCount
llDone = .T.
DO WHILE lnForms > 0 AND llDone
llDone = _SCREEN.Form(lnForms).QueryUnload()
IF llDone
_SCREEN.Form(lnForms).Release
lnForms = lnForms - 1
ENDIF
ENDDO
This loop would immediately terminate, if one of the form could not be closed, so the rest of forms would be left opened.

This is the code from Nick Neklioudov:
If there is no code in QueryUnload, it can be just like this:



********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: Nick Neklioudov
* Modified by.......:
********************************************************************
local lnForms, i
lnForms = _screen.formcount
FOR i = lnForms to 1 STEP -1
_screen.Forms(i).Release
ENDFOR
Another code is provided by Ed Rauh:

********************************************************************
* Description.......: Release all open forms
* Calling Samples...:
* Parameter List....:
* Created by........: Ed Rauh
* Modified by.......:
********************************************************************
With _Screen
for i = 1 TO .ControlCount
.RemoveObject(.Controls(.ControlCount).Name)
endfor
Endwith
CAUTION This approach would fail in situations, where forms may contain object refs, especially to other Form objects; the reason is that if you fail to release a Form that contains an object ref to another Form, or a control owned by another form, before releasing the referenced Form, the referenced Form will fail to Release as a result of a dangling object ref. i.e:

Form1 is instanced
Form2 is instanced, and holds an object ref to Form1 called Form2.oForm1Ref

If Form2 is released, and then Form1 is released, both Forms release normally
If Form1 is released before Form2, the object ref Form2.oForm1Ref still exists, and the object Form1 is not released, since there's still an active reference to the object Form1. If Form2 is now released, a dangling object Form1 remains with no means to clean it up and close normally. In order to find the dangling object reference you can use David Frankenbach utitlity (available for download from his site)
Thanks to Ed Rauh for this warning

In addition, the following code may be used: ( see
Coding, syntax & commands Re: How to Abort Thread #448407 Message #448450)



********************************************************************
* Description.......: Depart
* Calling Samples...:
* Parameter List....:
* Created by........: Ed Rauh
* Modified by.......:
********************************************************************
FUNCTION Depart
LPARAMETER tlNoDebug
CLEAR EVENTS
POP KEY ALL
SET ASSERTS ON
ON SHUTDOWN
DEACTIVATE WINDOW ALL
_SCREEN.Hide()
SET SYSMENU TO DEFAULT
SET LIBRARY TO
ASSERT _SCREEN.Show() AND ''=SYS(3056) AND tlNoDebug 'Forms Deactivated'
WITH _SCREEN
DO WHILE .FormCount > 0
.Forms(.FormCount).Release()
ENDDO
ENDWITH
ASSERT tlNoDebug 'Forms Released'
RETURN .F.





>Hi
>
>I have a lockout timer that runs throughout my app and when it's time to shutdown the app, it calls it's standard Quit() method in one of the objects. However, this method sometimes fails when certain forms are open.
>
>Is there any way I can close the application without it complaining about this and that, no if's and but's, it's a matter of fact, it WILL shutdown immediately!
>
>Any ideas?
>Thanks
>Kev
Stephen McLaughlin
"Sexy Steve Valenteno", "Blastmaster"
stephenmclaughlin@gmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform