Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find and Close all Instantiated Forms
Message
From
04/02/2009 23:54:48
 
 
To
03/12/2008 16:23:04
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01365406
Message ID:
01379387
Views:
29
>I am having issues with a graceful (cannot access selected table errors) exit when simply calling OnShutDown() with an open form.

Amanda, it just happens that I was working on this exact problem. My framework is a transmogriphication of the VFE framework which has a commong ancestry with MM.

Read through this code. It may give you some ideas.

Peter
***********************************************************************
**METHOD        VFEApplication.ReleaseForms|
***********************************************************************
**Purpose.....: End the application.
**               Called by the cleanup method, attempts to release all forms.
**Parameters..: none
**Returns.....: logical -- true if successful
**Notes.......:
**      This method attempts to release all active forms and returns
**      a logical value to indicate its success or failure. This was added
**      to make sure that all forms could be released before exiting an
**      application.
**Created.....: VFE
**History.....:
**08/11/97 - added an extra checks to make sure a form is an object for
**  safety's sake and eliminated code that had previously been commented out.
**************************************************************************
procedure ReleaseForms
*[2007/02/15 23:23:20] dragan - added tnOverride parameter to release all remaining forms
&&RS 2009.01.21 PRR2 Looks like this tlOverRide parameter is not doing anything helpful
&&RS 2009.01.28 PRR2 Removed tlOverRide parameter

**WAIT WINDOW "VFEApplication.ReleaseForms"

local   lcFormNames
local   llRetVal
local   lnForm
local   lnSkip  
local   loForm

llRetVal  = .t.        && assume success at this point
lnSkip    = 0

**-- Loop through all open forms and request that they be closed
for lnForm = _screen.formcount to 1 step -1
    if type("_SCREEN.Forms(lnForm).Name") = "C"
        loForm  = _screen.forms(lnForm)
        
        **Don't release toolbars that happen not to be docked,
        **let their formsets handle it.
        if upper(loForm.baseclass) = "TOOLBAR"
            lnSkip  = lnSkip + 1
            loop
        endif

        **Don't release the error handler form. We'll get it elsewhere
        if IsA(loForm,"frmErrorHandler")
            lnSkip  = lnSkip + 1
            loop
        endif

        &&RS 2009.01.21 PRR2 Don't release the status form here
        if loForm.Name == "FrmStatus"
            lnSkip  = lnSkip + 1
            loop
        endif                

        if glAbort_RS    &&RS 2009.01.30 PRR2
            ** Try to cancel changes in forms that are still open
            if pemstatus(loForm,"cancel",5)
                loForm.cancel()
            endif                    
        endif

        do case
        case empty(loForm.name)    &&RS 2009.01.30 PRR2
            ** For example, forms for report output
            loForm.release()
        case loForm.queryunload()
            **It is assumed that if the QueryUnload method of a form
            **returns .T. that it's release method will not fail.
            loForm.release(.t.)
            &&RS 2009.01.30 PRR2  if type("_SCREEN.Forms(lnForm).Name") = "C"
                *[2007/02/14 17:41:46] dragan - release won't fire if .destroy is called directly,
                *-- but calling .release will imply .destroy(), therefore commenting-
                *!*      _screen.forms(lnForm).destroy()
            **  _screen.forms(lnForm).release(.t.)
            &&RS 2009.01.30 PRR2  endif
        otherwise
            llRetVal  = .f.
        endcase
    endif
endfor

** Make a list of the forms that are still open.
lcFormNames = "~"  
for lnForm = _screen.formcount to 1 step -1
    if type("_SCREEN.Forms(lnForm).Name") = "C"
        lcFormNames = lcFormNames + _screen.Forms(lnForm).Name + "~" 
     endif
endfor

** If the number of forms in the list is greater than the number
** of forms intentionally skipped above, we have a problem.
if StrCount_RS(lcFormNames) > lnSkip
    llRetVal  = .f.           
endif
return llRetVal
endproc
Peter Robinson ** Rodes Design ** Virginia
Previous
Reply
Map
View

Click here to load this message in the networking platform