Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FOR EACH oFOrm
Message
 
To
01/11/2000 12:16:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00436742
Message ID:
00436750
Views:
22
Hi Christian,
What you are experiencing is a logic problem that stems from the fact that a FOR/EACH is really just doing a FOR x = 1 TO FORMCOUNT for you. If you think about it, you can see what is happening. Let's say you have four forms open. Form1, Form2, Form3 and Form4. When you do
FOR EACH oForm IN _SCREEN.FORMS
FoxPro looks at the formcount and sees 4. So, it's going to try and walk through 4 forms for you and close them. FoxPro issues the equivalent of
_SCREEN.FORMS(1).RELEASE()
. This closes the first form. Now, your _SCREEN.FORMS holds: Form2, Form3, and Form4. FoxPro now looks to close the second form by doing the equivalent of:
_SCREEN.FORMS(2).RELEASE()
. If you look at the _SCREEN.FORMS that you have, you'll see that this will close Form3. Now your _SCREEN.FORMS looks like this: Form2, Form4. FoxPro now tries to issue the equivalent of
_SCREEN.FORMS(3).RELEASE()
and
_SCREEN.FORMS(4).RELEASE()
Since these don't exist, nothing happens.

What you'd really like to have is a way to step through the forms backwards, so this wouldn't happen. The code below will do that for you:
------------------
FOR x = _SCREEN.FORMCOUNT TO 1 STEP -1

	_SCREEN.FORMS(x).RELEASE()

ENDFOR
-------------------
I hope this helps.

Marty

>Hello,
>I'm struggling with a FOR EACH/ENDFOR loop:
>When more than one form is open:
>
>FOR EACH oForm IN _SCREEN.FORMS
> oForm.RELEASE()
>ENDFOR
>It works only for the first form, the next form(s) are not triggered in this loop.
>Can anyone explain why this happens?
>
>Any help is highly appreciated!
Marty Smith, CSQE
Previous
Reply
Map
View

Click here to load this message in the networking platform