Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Controlling another form from current form
Message
De
21/12/1999 01:38:06
 
 
À
21/12/1999 01:03:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00284853
Message ID:
00306562
Vues:
24
>Hi Edward,
>
>I found this thread because I was searching on how to release a form from within another form. Neither forms were part of a class. I found the code below and and used it and it worked great. I just don't know WHY???
>

FOR EACH...ENDFOR iterates through a collection or array, changing the referenced collection member on each iteration. I've gone and marked the current object reference in my commentary in italics. In the case you show:

FOR EACH oForm IN _SCREEN.Forms

_SCREEN.Forms is a collection of active VFP Form objects. The FOR EACH statement iterates through the collection, and on each iteration, points oForm to the 'next' collection member. Within the context of the FOR EACH...ENDFOR, oForm is an object reference in this case, with a VARTYPE() of "O", because the members of the collection are object references. If instead, it were a collection of strings, each iteration would point oForm to the currently referenced string, and oForm in that context would have a VARTYPE() of "C"

IF oForm.Name=='startup'

On each iteration, you check the Name property of the currently referenced _SCREEN.Forms member.

oForm.Release

If the name property of the object referenced by oForm matches your condition, trigger the RELEASE method for the object.

>My code looks like this:
>
>For Each oForm In _SCREEN.Forms
> IF oForm.Name=="startup"
> oForm.release()
> Endif
>Endfor
>
>I don't see how when I say oform.release, that vfp knows which form I'm wanting to release.??? Or maybe it's coming to me now. Does oForm hold a reference or something to my form, and if so how? Still confusing. . . Can you help me a bit here? Oh and thanks again.
>

FOR EACH iterates the collection without using an explicit item reference. You can see the parallel between FOR...NEXT and FOR...EACH by looking at the following two code fragments:
FOR i = 1 TO _SCREEN.FormCount
   ? _Screen.Forms(i).Name
ENDFOR

FOR EACH oForm IN _SCREEN.Forms
   ? oForm.Name
ENDFOR
Why use FOR EACH? At the top of the list is that the number of members of the collection can change during the FOR EACH iteration without blowing up! If you release a collection member, the collection's count will change, and your FOR...NEXT loop will iterate past the last member, giving an Invalid subscript reference error.

Second IMO, is that the code is more readable. You can get several layers deep into collections and the explicit iterated object reference can get a bit hairy to read and understand.

Third, you don't have to worry about whether the collection or array is 0-based or 1-based when you write the code inside the context of FOR EACH...ENDFOR, and being the lazy SOB I am, and not caring about the ordering of the collection explicitly, it's one less thing to screw up when writing the loop.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform