SAMPLE: Formexit.exe EXIT Command May Leave Form Object Visible

ID: Q184218

The information in this article applies to:

SUMMARY

Formexit.exe is a sample file that that shows how adding an EXIT command to a FOR...NEXT loop that iterates through a series of Application.Form objects can leave a form object on the desktop. The example also provides a workaround to the problem.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

~ Formexit.exe

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online Services

This example has three forms, One, Two, and Three that sequentially appear. In the Activate event code of each form, a FOR...NEXT loop uses the Application.Form object to check if a form exists and changes the Caption property of a label object. If the FOR...NEXT loop is terminated by an EXIT command, it prevents Visual FoxPro from discarding the first form, and the form is left in memory.

To work around this problem, remove the EXIT command from the FOR...NEXT loop. This change allows the loop to complete, and the first form disappears.

Steps to Reproduce Behavior

1. Copy the Formexit.exe file to a directory on your system and run it to

   extract the sample files.

2. To run the application and follow the instructions on the forms that
   appear, type the following in the Command window:

      DO Formexit.app

   After following the instructions, the form titled One remains on the
   desktop.

3. To exit the example, activate form Three and press the Clear Events
   button. Activate the Command window by pressing the CTRL and F2 keys
   simultaneously and type "CLEAR ALL" (without quotes) in the Command
   window.

4. To implement the workaround, modify the project, open Frmone and open
   the Activate event. Comment the EXIT command by placing an asterisk (*)
   character in front of the line.

5. Repeat the same steps to the other two forms.

6. Rebuild the application and run the application file. Notice that Frmone

   now closes properly.

Keywords          : kbVFp 
Version           : WINDOWS:5.0,5.0a
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 25, 1998