' ... as safe as the for-next loop ...'
Not always. I learned the hard way, in PEM Editor, that even using FOXOBJECT was not always safe. Eventually I replaced all my loops with for-next loops, and my C5 errors disappeared.
>>Bernard nailed it. I've found that the issue is with the for-each construct. If you simply interate through using a standard For-next loop, referencing each item in the collection, you don't get any dangling references
>>
>>FOR x = 1 TO oCollection.Count
>> oItem = oCollection.Item(x)
>> * do whatever you need here
>>NEXT
>>
>>Give that a shot and see if the problem persists.
>
>BTW, you can still use the "for each ... in ..." if you include the "FOXOBJECT" clause in the end of the line. Originally, the for-each loop was a COM object and its interface was heavy for that, but at least it allowed for parsing collections in COM objects. The downside was that it was somewhat buggy when parsing Fox collections and arrays, which is why we got this clause in VFP9. With that clause, it uses native Fox objects, no COM interface, and is then as safe as the for-next loop.
Jim Nelson
Newbury Park, CA