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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing form from another form 1

Status
Not open for further replies.

jester4281

IS-IT--Management
Sep 12, 2002
160
0
0
US
Is there a way to close form A from form B

Ex.
Thisform.Release() but it would be form B, like a B.release()
 
Yes it is. Designate name to the form. Then FormName.release should work.

Also, _screen.form array should work:
_screen.forms[3].release
 
Hello Jester4281.

>> Is there a way to close form A from form B <<

Is form A being instantiated from Form A. If so, you can pas an object reference to form B from Form A like so:

Code:
DO FORM FormB WITH This

Add a custom property to FormB called oParent and in Form B's Init():

Code:
LPARAMETERS toParent
Thisform.oParent = toParent

This code in Form B's Destroy:

Code:
This.oParent = .NULL.

And when you want to release Form A from Form B:

Code:
This.oParent.Release()
This.oParent = .NULL.



Marcia G. Akins
 
Inside foxpro the search_screen.release works fine, but in the compiled version it says the object can not be found.

What I Have is a form with a toolbar class on it, when the users selects one of the buttons I need for it to close the other forms.
 
_screen.forms[3].release work for me in compiled exe version just fine.
 
Hello Jester4281.

>> What I Have is a form with a toolbar class on it, when the users selects one of the buttons I need for it to close the other forms. <<

How about something like this:

Code:
FOR EACH loForm IN _Screen.Forms
  IF LOWER( loForm.Name ) == 'search_form'
    loForm.Release()
  ENDIF
ENDFOR



Marcia G. Akins
 
How would I get that to work Marcia.


FOR EACH loForm IN _Screen.Forms
IF LOWER( loForm.Name ) == 'search_form'
loForm.Release()
ENDIF
ENDFOR


what is loForm, is that the target form I am looking to close if open ?
 
Assuming that you know the form name of "A" (such as: "MyFormA"), rather than searching through all possible forms which may be open on the _SCREEN to find the one you want, then it is simpler to just specifically reference it.

From within Form "B"...
MyFormA.Release

Good Luck,
JRB-Bldr
 
Hello Jester.

>> what is loForm, is that the target form I am looking to close if open ? <<

The _Screen object in VFP has a forms collection which holds an object reference to all open forms. So loForm is the current form in the collection. So, yes. It might be the target form you are looking form. If you know what its name:

loForm.Name

or caption:

UPPER( ALLTRIM( loForm.Caption ) )

id, you have some way to identify whether or not the current form in the collection is the onle you are looking for.

Then you can just issue a

loForm.Release()

to close it



Marcia G. Akins
 
According to my experience

From within Form "B"...
MyFormA.Release


works fine, but surprisingly MyFormA is not a name property of the form, but the name of the file (without the extension SCX), where the form is stored on the disk. If file name is MyFormA.scx, then MyFormA.Release is OK, else one must write FileNameWhereFormAIsStored.Release

By Tom
 
Tom - I have not experienced what you say.

I have a Form "QC LEADS.SCX"
which has a Name property QC_LEADS

When I externally reference the Form from another Form, I have to use the QC_LEADS reference for it when it is running (in background, hidden or whatever) or the command will not work.

Good Luck,
JRB-Bldr
 
JRB-Bldr
I know that what I've said about my forms "naming and referencing" experience looks like stupidity and I also know that - in others word – I was saying VFP has a serious bag

But in my FoxPro environment it's completely true and I am very unhappy with it.
For forms I'm always using names like frmNewClient, but store them on disk like NewClient.scx - without prefix frm, because suffix SCX is enough.. NewClient is also the name to be seen in Project manager.

If I write NewClient.release – everything's OK. If I write frmNewClient.release – then Program error: Object frmNewClient is not found.

For other readers (and for me first) would be great to solve this dilemma here, because I believe that we both are true. Will you help?

What circumstances and settings are relevant to this situation – it's hard to say, but for the beginning I start with:

- My VFP version is 5.0a (maybe I'd say it sooner)
- I run forms with command DO FORM FormName (here again FormName is a filename.scx, not form's property name) without additional clause NAME (My God, here could be the difference)

Tom
(Sorry for my English, I've been learning it for 45 years but still nothing)
 
Hello JrbBldr and Tom.

This is from the VFP 8.0 help file on the DO FORM command. I suspect that it has not changed much since version 5 <s>. This is what it says about the "NAME VarName [LINKED] clause (which should resolve your issues).

NAME VarName [LINKED]
Specifies a variable or array element with which you can reference the form or form set. If you specify a variable that doesn't exist, Microsoft Visual FoxPro automatically creates it. If you specify an array element, the array must exist before you issue DO FORM. If the variable or array element you specify already exists, its contents are overwritten.
If you omit the NAME clause, Visual FoxPro creates an object type variable with the same name as the form or form set file.

Include LINKED to link the form to the variable associated with it so that the form is released when the variable goes out of scope. If you don't include LINKED, a form can still be active, even though there is no object variable associated with the form.



Marcia G. Akins
 
Thank you all, you all had helpful post, I found that Marcia's method worked to the T, thank you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top