Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FOR EACH....
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00111062
Message ID:
00111128
Vues:
21
This is somehow normal. The FOR EACH blabla IN ThisForm.Controls works fine if you don't remove/add objects from/to the collection inside the loop.

Here's what happens when controls are removed inside the loop:
Let's say we have 3 objects: o1, o2, o3.
First loop: removes o1 and the collection is now o2, o3.
Second loop: removes the *second object* from the collection and the collection becomes o2.
Third loop: already greater than the number of objects in the collection, FOR EACH ends.

You can see this clearly if you add a
wait wind oControl.Name
before the RemoveObject in your code.

In other words, FOR EACH scans a list that looses elements inside the loop. There is nothing there to tell VFP to not "move to the next element" when an object is removed.

The only way to implement such a method is to use a loop command (DO WHILE) for which you can control the "go to next element" action.

Knowing nothing about the internal implementation of FOR EACH, I would say that adding/removing elements to/from the scanned collection is at least risky. What works today may not work tomorrow...

Vlad

>I placed your code in Form.DblClick() and it worked. The funny thing I noticed that the objects didn't disappear all at once - I had to doubleclick 3-4 times to have them all gone.
>
>Nick
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform