Actually a better solution may be to update the ctlGetParentForm function contained in ctl32_functions.prg by doing a type check on the return value like this:
Function ctlGetParentForm(m.poForm As Form)
Local ;
m.lnHwnd As Integer, ;
m.loForm As Form, ;
m.lnX As Integer
m.lnHwnd = apiGetParent(m.poForm.HWnd)
If _Screen.HWnd = m.lnHwnd Then
m.loForm = _Screen
Else
*!* Parent is a Top Level Form, get HWnd of form, what we have
*!* now is HWnd of inner window of Top Level Form:
m.lnHwnd = apiGetParent(m.lnHwnd)
*!* Find the Top Level Form that has this HWnd:
For m.lnX = 1 To _Screen.FormCount
If _Screen.Forms(m.lnX).HWnd = m.lnHwnd Then
m.loForm = _Screen.Forms(m.lnX)
Exit
Endif
Endfor
Endif
_*!* - rk - 2013-3-6 - another solution to insuring that the return value is an object
IF VARTYPE(m.loForm)<>[O]
m.loForm = _Screen
ENDIF
_ Return m.loForm