Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
For each doesn't release all forms?
Message
De
07/10/2010 08:08:53
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01241310
Message ID:
01484307
Vues:
80
This message has been marked as a message which has helped to the initial question of the thread.
>>>So, what is the solution to the problem of removing item from collection while iterating through it if I don't want to start from last item?
>>>
>>>Update. I think if I will always remove the first item
>>>
>>>for lnI = 1 to Collection.Count
>>>   oItem[1].Remove()
>>>next
>>>
>>>will work
>>
>>It will work but usually you will have a conditional removal and then this code will not be useful (You could've use Remove(-1) to remove all items). You could always use a two pass procedure, in the first pass you determine the items you want to delete and store its keys in an auxiliary object (another collection, a cursor an array etc) then your second pass would be to scan that auxiliary object and use the keys to remove the items from the collection.
>
>Yes, but I don't like it either. What about backward removal, does it always work? Perhaps it doesn't matter in my case and actually removing from the last item may be better (I'm trying to delete multiple selected items in the Item Tree).

Yes, backward removal will always work:
FOR nItem = oCollection.Count TO 1 STEP -1
  oCollection.Remove(m.nItem)
ENDFOR
Tamar
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform