>>I have just started working with VFP5.0, I have worked with 2.x for about 8 years. I really like the OOP stuff, but I'm still a little bit overwhelmed.
>>
>>I have some forms that I have defined as MODELESS so that other forms may be run. However, I only want the user to be able to run a single instance of a particular form. If the menu selection is made for a form that is already running, I want to change the focus to the existing form instead of creating a new form.
>>
>>A second problem that I am having is how to I "clean-up" the MODELESS forms when the EXIT is selected from the menu. When I select EXIT, I get the command window (I am not quiting at this point), and the forms are floating around doing "their thing" until they are individually closed.
>>
>>Thanks for your help
>>
>>Norm
>
>Hi Norm,
>You need a couple of functions that manage these issues for you. In general you should always run modeless unless you specifically must have a modeless form. You can modify the following code to control the multiple form problem. Other folks may do it quite differently to this; so I present it for ideas only...
>
>PROCEDURE DoForm
>LPARAMETER frmName
>LOCAL oFrm
>oFrm= GetForm(m.frmName)
>IF ISNULL(m.oFrm)
> * the name of the form and the name of the scx can be different and I always 'name' my forms beginning with 'frm'
> * assumes form name is like frmScxName => ScxName
> DO FORM (STRTRAN(m.frmName, "frm", "", 1, 1))
>ELSE
> oFrm.Show()
>ENDIF
>
>FUNCTION GetForm
>LPARAMETER tcFrmName, cCond
>* === returns a handle to the form named cFrmName
>* NOTE: Case and length sensitive
>* optionally locates the instance satisfying m.cCond
>* returns .NULL. if not found
>* Remember to eventually release variables being assigned the form name otherwise the form may not release
>LOCAL oFrm, oRetFrm, cFrmName
>cFrmName= ALLTRIM(UPPER(m.tcFrmName))
>oRetFrm= .NULL.
>FOR EACH oFrm IN _SCREEN.Forms
> WITH m.oFrm
> * if we have a form of the correct name, is it the instance we need (cCond)?
> IF UPPER(.Name) == m.cFrmName ;
> AND (EMPTY(m.cCond) OR EVALUATE(m.cCond))
> oRetFrm= m.oFrm
> EXIT
> *VVVVV
> ENDIF
> ENDWITH
>ENDFOR
>RETURN m.oRetFrm
>
>So you see I can force a form to load once only by going...
>Do Doform with "frmMyForm"
>
>I think my nameing convention here is a bit wacky :-)
>
>Here's some code that closes all forms too...
>FUNCTION ReleaseAllForms
>LOCAL ii, ok
>ok= .T. && ok will become false if one or more forms wont release
>FOR ii = _screen.FormCount TO 1 STEP -1
> IF TYPE("_screen.Forms(m.ii).name") = "C" ;
> AND _screen.Forms(m.ii).BaseClass == "Form"
> ok= _screen.Forms(m.ii).Release() AND m.ok
> ENDIF
>ENDFOR
>RETURN m.ok
You may also want to check out the ON SHUTDOWN functionality.
Bill Benton
Senior Systems Analyst
Nuvell Financial Services