Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening & closing forms from the menu

Status
Not open for further replies.

mep1

IS-IT--Management
Jun 18, 2003
67
0
0
US
Hi all,

Building a main menu to navigate through my various forms... what is the best way to open a new form and hide the current form from the menu?

I tried having the menu do a procedure:

Code:
DO FORM myForm.scx with ACTIVEFORM[\code]

and then in the init of myForm:

[code]PARAMETERS oFormRef
THIS.AddProperty('CallingForm')
THIS.CallingForm = oFormRef
THIS.CallingForm.visible = .F.[\code]

However, my menu is telling me that it can't find ACTIVEFORM... so I'm a little stumped

Thanks for the help!

-MEP
 
MEP,

What exactly is ACTIVEVORM? Is it a variable that you have created to hold the previously active form?

Or are you confusing it with _SCREEN.ActiveForm?

A slicker way of getting a reference to a calling form is to write code in the Load event. When the Load fires, the previously active form (if any) is still active. So you can easily get a reference to it, and save it in a property of the current form.

In your base form's Load event, add this code:

IF _SCREEN.FormCount > 0
THIS.oActive = _SCREEN.ActiveForm
ELSE
THIS.oActive = NULL
ENDIF

That way, you can call the form without passing the parameter.

(Thanks to Andy Kramek, who told me about this.)

Mike


Mike Lewis
Edinburgh, Scotland
 
Thanks Mike,

I think you misread... I indeed typed DO FORM myForm.scx with ACTIVEFORM (not ACTIVEVORM), figuring that the menu would recognize the topmost form as the ACTIVEFORM...

When I instead did:

Code:
DO FORM myForm.scx with _SCREEN.ACTIVEFORM[\code]

as you suggested, my problems were solved.

I do like the alternate method you mentioned, seems very slick and efficient... might have to give it a try!

Cheers for the help

-MEP
 
Thanks Mike,

I am very new to FoxPro and find your posts very helpful. While developing this application I have been very careful to strictly control the interactions between forms.

In the above example, I have strictly enforced that there is in fact a form open when I execute the DO FORM WITH _SCREEN.ACTIVEFORM command.

Even if I _know_ that there is a form open would you still advise adding some error checking code to make _sure_ that a form is open?

Cheers,

MEP
 
MEP,

Even if I _know_ that there is a form open would you still advise adding some error checking code to make _sure_ that a form is open?

Yes. After all, one day things might change .. you might want to apply your form opening code in a situation where you don't know if a form will be open or not. It's a good aim to try to make code generic. If you can write a snippet of code that can be used regardless of whether there is a form open, that would be a good thing to do.

One way to do that would be something like this:

loActive = IIF(_SCREEN.Formcount>0,_SCREEN.ActiveForm,NULL)
DO FORM xxx WITH loActive

Then, if no form is open when that code is called, the form will receive a NULL rather than an object reference.

Mike


Mike Lewis
Edinburgh, Scotland
 
I did a search and looked for a FAQ with no luck.

I would like to have a "Windows" menu item that shows all the currently-opened forms. Some of my forms can have multiple copies open. I use the following code to populate the list of open forms and to bring the selected form into focus. I am calling this code on the Init and Unload events to update the list of open forms. However, the Unload event fails to update the list because the form still exists. Any suggestions on a methodology?

---code used----

RELEASE BAR all OF Windows

i = 0
FOR EACH loFrm IN _SCREEN.FORMS
i = i+1
DEFINE BAR i OF Windows PROMPT ALLTRIM(STR(i)) + '. ' + loFrm.Caption
lcFox = "ON SELECTION BAR i OF Windows DO _MenuChg WITH " + STR(i)
&lcFox
ENDFOR

PROCEDURE _MenuChg
LPARAMETERS ln
_Screen.forms(ln).Show()
_Screen.Forms(ln).WindowState = 0
_Screen.Forms(ln).AutoCenter = .T.
ENDPROC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top