Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Question about handling Forms
Message
From
26/02/1999 03:00:47
Bill Benton
North Florida Software Services
Middleburg, Florida, United States
 
 
To
25/02/1999 00:36:15
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00191274
Message ID:
00191832
Views:
25
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform