You are here:

FoxPro/Unload/Release Forms while in Main Form

Advertisement


Question
Markish,


I'm trying to release all forms loaded in the MainForm when i click LogOFF button. I'm getting an error 'Object 'name' is not found.' when I issue a release command.

Here is my code to RELEASE the forms.
Local instance_ct As Integer
Local lcCmd As String

instance_ct   = 0
For ii=1 To _Screen.FormCount
  If Upper(_Screen.Forms(ii).Name) <> Upper('frmMainForm') THEN
     lcCmd = Alltrim(_Screen.Forms(ii).Name) +'.Release'
     &lcCmd
  Endif
Next ii

Or do you have any suggestion on how to do my LOGOFF routine.

Thanks in advance.


Best regards,

FLeX
VFP7 Developer

Answer
Hi Flex,
   I had a look at your code, It's a small problem. Moment you release one form, the total number of forms get reduces. Hence if you try to refer one of the form with form(ii) that is not exisiting... It gives an error. I'm not sure if you want to close all other forms but for the frmmain. For this you can store the forms to be closed into an array and close them. Code like below will do

DIMENSION mactive_forms(100)
frm_ct=0
FOR ctr=1 To _screen.FormCount
  If _Screen.Forms(ctr).Name<>Thisform.Name
     frm_ct=frm_ct+1
     mactive_forms(frm_ct)=_Screen.Forms(ctr)
  ENDIF
ENDFOR
IF frm_ct>0
  FOR ctr=1 TO frm_ct
     mactive_forms(ctr).release
  ENDFOR
ENDIF

If you want to close all the forms otherwise, you can use
FOR ctr=_screen.FormCount TO 1 STEP -1
  _Screen.Forms(ctr).Release
ENDFOR

Hope this helps...
Best regards,
Markish
http://markishonline.com

FoxPro

All Answers


Answers by Expert:


Ask Experts

Volunteer


Markish

Expertise

I can answer general questions related to Foxpro from Version 2.0 to 9.0. I'll try to answer them as quickly as possible.

Experience

I've been into Dbase programming from age of 11. I've worked in versions from FoxPro 2.0 and Foxbase.
Education/Credentials
I've done my B.Tech (IT) with distinction from Anna University, Chennai - India.

Education/Credentials
I've done my B.Tech (IT) with distinction from Anna University, Chennai - India.

©2012 About.com, a part of The New York Times Company. All rights reserved.