>>>>Naomi,
>>>>
>>>>Usually you can not iterate with FOR EACH in any collection while adding or removing items. Your Step - 1 solution is correct, IMO
>>>
>>>Hmm, I'm not sure, this needs to be comfirmed. I thought "for each" should work even when adding or removing. I need to review my own FAQ again, I already switched to George's solution but it didn't help yet.
>>>
>>
>>I can confirm if you care:) Do not add/remove with a foreach (not in VFP, not in .Net - at least documented for .Net:)
>>Cetin
>
>I do, Cetin.
>
>Yes, now I can see that we can not use collection. I also need to re-check my FAQ.
>
>But for some reason even
>
>lnForms = _SCREEN.FORMCOUNT
>
> DO WHILE lnForms > 0 AND llExit
> IF PEMSTATUS(_SCREEN.FORMS(lnForms),'QueryUnload', 5)
> llExit = _SCREEN.FORMS(lnForms).QUERYUNLOAD()
> ENDIF
> IF llExit
> _SCREEN.FORMS(lnForms).RELEASE
> lnForms = m.lnForms - 1
> ENDIF
> ENDDO
>
>
>Didn't work yesterday. Do you know what may be wrong?
>
>Appreciate your response in advance.
I can see a series of reasons with this piece of code but unlikely you'd be trapped with some of them:
1) mdot, mdot please mdot.
2) lnForms = m.lnForms - 1 is suspicious code. What if there is one or more toolbars associated with a form or one is 'child' of another and released due its parent is released (ie: name linked).
lnForms = _screen.formcount
sounds better.
3) No guarantee that you could release a form like this. ie: what if one is waiting for a response, hanging object ref., valid etc.
4) forms are not guaranteed to be members of _screen, no check on _vfp.
5) I don't know:)
I'd instead use oApp's form collection and form manager (hope you have one such form manager).
Cetin