David,
I run very similar code with no problem at all.
for each loForm in _VFP.Forms
if vartype(loForm) = "O" and pemstatus(loForm, "BaseClass", 5) and loForm.Baseclass = "Form"
if !loForm.QueryUnload()
return .F.
endif
loForm.Release()
endif
endfor
I do have a cancel button on each of the forms, do you?
>I am unable to release forms programatically from the menu when there is a grid on the form and one of the cells on the grid has focus.
>
>It works fine when a textbox or combobox or checkbox has the focus, and works fine if the procedure is called from the command window. However when the procedure is called from the menu and a cell on the grid has focus, the form will not release until the procedure RETURNs.
>
>The stripped down procedure called from the menu or executed from the command window is:
>
>
PROCEDURE OPEN_INCIDENT
>LOCAL i as Integer, lFormsShut as Boolean
>
>lFormsShut = .T.
>
>FOR i = _Screen.FormCount TO 1 STEP -1
> * backwards because the form count will be changing
> IF UPPER(_Screen.Forms[i].BaseClass) == 'FORM'
> IF _Screen.Forms[i].QueryUnload()
> _Screen.Forms[i].Release(.T.)
> ELSE
> lFormsShut = .F.
> ENDIF
> ENDIF
>ENDFOR
>
>...
>
>Under the conditions that it works the forms release on the line _Screen.Forms[i].Release(.T.). Under the conditions that it does not work the forms will not release until the procedure executes the RETURN at the end. Unfortunately there is a lot of code between where the form should release and the RETURN that expects the forms to all be closed.
>
>The menu is created with the Menu Designer, this is in VFP 8 SP 1 on a Windows XP Professional machine with all the lastest service packs.
>
>Any suggestion appreciated since I have just about torn out all my hair over this one.
>
>Thanks in advance,
>David
Caroline