Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_screens.forms - Array not accurate

Status
Not open for further replies.

Imaginecorp

IS-IT--Management
Jan 7, 2007
635
US
Had to repost in forms, controls ....

Olaf; decided against doing a manual shutdown...Will force the user to shutdown by displaying a message that some forms are open and to close them...

Thanks for your input though...
 
Hello Craig;
The forms array seems to miss a object when there are multiple ones open. When a user clicks the Exit button to exit out of our application, with forms open we display a message asking the user to either close the forms down or the allow the app to do it.
Code:
For Each oform To _Screen.Forms
 If oform.BaseClass = "Form"
  ..... Message To User
  .....code 
  ..... code
  oform.Release
 Endif
Endfor
the above partial routine leaves one form open i.e. destroy does not fire, there are No hanging refrences as if there were, the destroy of the form would fire but the form would remain open.
The reason to check If ..."form", is there is a toolbar also which will close by itself later in the exit routine...
 
Imaginecorp,

What you seem to be doing is looping through the forms in the Forms collection, possibly closing forms - and therefore removing them from the collection - as you do so. I'm not sure if that would work, but it seems to be courting trouble.

Something like this might be better:

Code:
DO WHILE _Screen.Formcount > 0
  oForm = _Screen.Forms(_Screen.Formcount)
  IF <you want to close this form>
    oForm.Release
  ELSE
    EXIT
  ENDIF
ENDDO

My apologies if this doesn't achieve what you want, but the first part of the thread seems to have disappeared, so I'm only guessing what this is about.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
This issue is known, but not a bug. It has to do with how items are removed from the list in the loop. What you need to do is loop backwards through the list, not forwards.

Craig Berntson
MCSD, Visual FoxPro MVP,
 
Imaginecorp,

my solution was not to loop backwards but to do this loop:
Code:
* ask user if all form should close
* in case he wants that:
Do While _screen.formcount>0
   oForm = _screen.forms(1)
   oForm.release()
Enddo

This will also loop through all forms, it will not always adress the same forms(1) form, as the release will rearrange the array. For the same reason you skip a form, because if you close form1 and loop to form2, there is a new form1, that was previously form2 and form2 in the second iteration of the loop initially was form3, so you only close form1 and form3.

While you can llop backwards, you can also do it in array order, but you need to consider, that because of releasing the form you modify the array. It's not static, it will shrink. Therefor always adressing _screen.Forms(1) will also work, as long as there is no form that has a problem in closing.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top