Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strange behaviour in deleting object
Message
De
09/08/2006 10:35:39
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
09/08/2006 09:31:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01143804
Message ID:
01144139
Vues:
21
>I thought about it but it is a nonsense as i do the job with the loop
>
>for i = Myobj.controlcount to 1
>endfor
>
>I supposed there was something like hidden index as Fabio told me but I wanted to be sure about it. :-)

It's just that you're going down the list while deleting from the list. So the list changes below your feet, so to speak. When you delete element #1, what happens to the list? Does element #1 become empty, or does element #2 become #1, and #3 become #2? That's surely the case with some of object collections (like _screen.forms), and that'd be the explanation why deleting from the end

for i = Myobj.controlcount to 1 step -1
myobj.removeobject(myobj.controls[i].name)
endfor

works, while going up it deletes only odd elements while keeping the even ones.

Somewhere in the help I read that For Each is supposed to be immune to this skipping, and should work regardless of how many elements you insert or remove - but Sergey found this not to be the case.

My heavy handed solution was for the case where even ...step -1 doesn't work, if there's such a case.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform