Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Closing all forms
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00159684
Message ID:
00159836
Views:
33
Michelle,

You can't loop through the Forms[] collection in the forward direction like has been recommended by others. When Form[1] is released Form[2] moves down to Form[1], but your index goes up to 2 which will now release what was originally Form[3].

There are two ways around this. Loop backward through the forms ie N TO 1 STEP -1 or just always use [1] as the index. It can get more complicated though if you have parent-child forms and closing the parent causes the child to be closed. My current CloseForms udf is:
* 15-Jun-98 CloseForms.prg

* 15-Jun-98 made into separate program

procedure CloseForms

for i = _screen.FormCount to 1 step -1
   * 15-May-98 added additional tests to prevent 1924 error
   if ( ( i <= _screen.FormCount ) and ;
        ( type( "_screen.Forms[i]" ) == "O" ) )
      if ( _screen.Forms[i].QueryUnload() )
         _screen.Forms[i].Release()
      else
         _screen.Forms[i].Activate()
      endif
   endif
endfor
>I need to close all the forms so the user can relogon to a different database. I'm thinking I need to do something with _screen and controls[], but I'm not sure what syntax I need.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform