Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange behaviour in deleting object
Message
From
09/08/2006 10:35:39
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
09/08/2006 09:31:33
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01143804
Message ID:
01144139
Views:
12
>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.
Previous
Reply
Map
View

Click here to load this message in the networking platform