Your assessment is similar to mine. Craig would call it a "dangling reference". Maybe VFP needs an "active" object to fall back on when objects are removed. If VFP does not have an "active" reference, a C5 is raised.
The GOOD NEWS, at least according to Sergey, is that VFP 8 does not raise a C5!
There is another way to force a C5 with this example. It's nice to know that C5 does not necessiarily mean the end of the world (I would have had a hard time rescoping the project!)
>Hi Terry,
>
>I think that the source of the problem is simply that when Foxpro tries to return focus to the Commandbutton it has been destroyed....
>
>Here's a stripped down version of your code that demonstrates the same error:
>
>* C5.prg
>CLOSE ALL
>RELEASE ALL
>CLEAR ALL
>PUBLIC frmC5
>frmC5=CREATEOBJECT('subform')
>frmC5.SHOW
>READ EVENTS
>CANCEL
>
>DEFINE CLASS subForm AS FORM
> NAME='frmC5'
> BACKCOLOR=RGB(255,0,0)
> AUTOCENTER=.T.
> PROCEDURE QUERYUNLOAD
> CLEAR EVENTS
> ENDPROC
> ADD OBJECT cntbig AS subBigContainer
>ENDDEFINE
>
>DEFINE CLASS subBigContainer AS CONTAINER
> BACKCOLOR=RGB(255,255,255)
> ADD OBJECT cntSmall AS subSmallContainer
>ENDDEF
>
>DEFINE CLASS subSmallContainer AS CONTAINER
> * Uncomment next line to get C5 <<-----------------------------
> * ADD OBJECT cmdRemoveObj AS subRemoveObj
> PROCEDURE CLICK
> THISFORM.cntbig.REMOVEOBJECT('cntsmall')
> ENDPROC
>ENDDEF
>
>DEFINE CLASS subRemoveObj AS COMMANDBUTTON
>ENDDEFINE
>
>* END C5.PRG
>
>
>Didn't have time to play with this for long but it also seems that the behaviour only occurs with a nested container - removing 'cntBig' with a contained commandbutton doesn't cause a problem...
>
>Regards,
>Viv
Imagination is more important than knowledge