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

closing a form within a form 2

Status
Not open for further replies.

hoffmanhoward

Programmer
Joined
Jun 15, 2003
Messages
16
Location
US
I am using a form called "helpform" as a "help screen" within another form called "mainform".

I have an "exit" button on the "help" form to release it

and it does..However, If I don't release it and close the

form that it is in (mainform), "helpform" stays open. How to I write code so that when I release "mainform" it also releases "helpform"

Thanks
 
hoffmanhoward

In calling your second form, use the NAME clause:
do form helpform NAME oHelpform

Now you have a reference to the second form and since there are two ways to close the form, when you close the main form (assuming your help form is still up), check form the oHelpform variable if is is still there, and if it is relase that one to. (In the queryUnload of the mainform)
IF TYPE("oHelpForm")="O"
oHelpForm.release()
ENDIF



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 

This is what I did:

the mainform is called "pamenu"
the help menu is called "helppamenu"


in the click event of a command button on the pamenu form

I put: DO FORM c:\homewell\helppamenu NAME HelpPAMenu


In the queryUnload of "pamenu" I put:

IF TYPE("HelpPAMenu")="O"
HelpPAMenu.release()
ENDIF

I have an "exit" command button on "pamenu" that has
in the click event: thisform.release

Is this all I need ? I must be missing something because
I open pamenu then , if I open pamenuhelp, and then click "exit" on the pamenu, pamenu is released but
pamenuhelp does not close if it is open

What am I missing or doing wrong ??
 
Is this all I need ? I must be missing something because
I open pamenu then , if I open pamenuhelp, and then click "exit" on the pamenu, pamenu is released but
pamenuhelp does not close if it is open


Try using
PUBLIC oHelpMenu && Note the added "o" to differentiate
DO FORM c:\homewell\helppamenu NAME oHelpPAMenu
IF TYPE("oHelpPAMenu")="O"
oHelpPAMenu.release()
ENDIF




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
There are two problems there.

1. use FORM properties or declare a public variable as Mike has suggested.

- add "HelpPAMenu" properties to Form "pamenu"
- in the click event of a command button on the pamenu form
DO FORM c:\homewell\helppamenu NAME thisform.HelpPAMenu


2. QueryUnload event doesn't fired when you issued thisform.release. Change it to Unload event.

In the Unload of "pamenu"

IF TYPE("This.HelpPAMenu")="O"
This.HelpPAMenu.release()
ENDIF

It should work now

-- AirCon --
 
O.K. I put:
PUBLIC ohelppamenu
DO FORM c:\homewell\helppamenu NAME ohelppamenu

In the click event of a command button on Pamenu

I put:

IF TYPE("ohelppamenu")="O"
ohelppamenu.release()
ENDIF
In the Queryunload of pamenu
it did not work


so I tried putting

PUBLIC oHelppaMenu
DO FORM c:\homewell\helppamenu NAME ohelppaMenu

in the click event of a command button on Pamenu

and I put:

IF TYPE("oHelpPAMenu")="0"
ohelppaenu.release()
ENDIF
in the unload of pamenu and that didn't work either.
helppamenu window is still open.

am I still doing something wrong ??

 
I think so. I assumed your last code is just a typo :-)
Try this code:

PUBLIC oform1

oform1=NewObject("form1")
oform1.Show
RETURN


DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 180
Width = 247
DoCreate = .T.
Caption = "Form1"
helppamenu = .NULL.

ADD OBJECT command1 AS commandbutton WITH ;
Top = 52, Left = 74, Height = 27, Width = 80, ;
Caption = "HelpPAMenu"

ADD OBJECT command2 AS commandbutton WITH ;
Top = 93, Left = 74, Height = 27, Width = 83, ;
Caption = "Close Form"

PROCEDURE command1.Click
Do Form c:\homewell\helppamenu name ThisForm.HelpPAMenu
ENDPROC

PROCEDURE command2.Click
ThisForm.Release()
ENDPROC

PROCEDURE Unload
If (vartype(ThisForm.helppamenu) == 'O')
ThisForm.helppamenu.Release()
endif
ENDPROC
ENDDEFINE


-- AirCon --
 
thanks..but I am really kind of new at this...

where to I put the code that you just gave me ??

and what about the other stuff in the previous help messages ?
 
Create a new PRG, name it test.prg (whatever)
Like this:

modi comm test.prg

Cut & paste the code, save and run it. Just to see it works or not.

Then move the procedure (one by one) into the event of your form. The name of the PROCEDURE from the code is the same with the name with event name in form.
i.e.:

PROCEDURE command2.Click

move to your "exit" command button click

and so on...


-- AirCon --
 
Hi Aircon,

Lastnight I was so happy when I got your program and tried it and it opened my helppamenu and then closed it with the other button but I had to leave at that point. This morning I got up and first thing I did was try to get my forms to work correctly.

I went to the click of my help button
and inserted:

Do Form c:\homewell\helppamenu name "ThisForm.HelpPAMenu"

and I got the error message:

Property HELPPAMENU is not found

What did I do wrong ???

If I remove "Thisform." it will open the help form
 
hoffmanhoward

Do Form c:\homewell\helppamenu name "ThisForm.HelpPAMenu"

Wasn't aircon suggestion :
Do Form c:\homewell\helppamenu name ThisForm.HelpPAMenu &&Without the quotes.

But then again, based on my experience, using the NAME clause to call a form using "THIS" in the name is just asking for trouble.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 


Do Form c:\homewell\helppamenu name ThisForm.HelpPAMenu

I'm sorry...I did run it without the quotes and got the error message : Property HELPPAMENU is not found
 
hoffmanhoward

Hence the reason I said "using the NAME clause to call a form using "THIS" in the name is just asking for trouble."

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Any suggestions...nothing has worked on my form to close the help window when I close the main form.
 
It is hard to do it in acutal forms in this forum, but here is retaking AirCon code and adding a second form (by code) that works for me:
Code:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return


Define Class form1 As Form
	Top = 0
	Left = 0
	Height = 180
	Width = 247
	DoCreate = .T.
	Caption = "Form1"
	helppamenu = .Null.

	Add Object command1 As CommandButton With ;
		Top = 52, Left = 74, Height = 27, Width = 80, ;
		Caption = "HelpPAMenu"

	Add Object command2 As CommandButton With ;
		Top = 93, Left = 74, Height = 27, Width = 83, ;
		Caption = "Close Form"
	Procedure command1.Click
	Public oHelpform
	oHelpform = Createobject("helpform")
	oHelpform.Show()
Endproc

	Procedure command2.Click
	If (Vartype(oHelpform) == 'O')
		oHelpform.Release()
	Endif

	Thisform.Release()
Endproc

	Procedure Unload
	If (Vartype(oHelpform) == 'O')
		oHelpform.Release()
	Endif
Endproc
Enddefine
Define Class helpform As Form
autocenter = .t.
Enddefine



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I copied your code and ran it

when I run Aircon's program and click on helppamenu I open my form called helppamanu

When I run your program and click on helppamenu I get a blankform called helpform

Maybe if you fix it so I can see my pahelpmenu form it might work.

Why is it difficult to do in actual forms ??

 
hoffmanhoward

Why is it difficult to do in actual forms ??

I meant it is difficult to show you how to do it, without actually having an actual form to do it with since this forum doesn't provide anyway to attach things to the message. I did not mean what you are trying to do is difficult.

When I run your program and click on helppamenu I get a blankform called helpform

As intended. Here is a modifcation to the code. Do not make you help form modal, and make sure the path to the second form is right.


Code:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return


Define Class form1 As Form
    Top = 0
    Left = 0
    Height = 180
    Width = 247
    DoCreate = .T.
    Caption = "Form1"
    Add Object command1 As CommandButton With ;
        Top = 52, Left = 74, Height = 27, Width = 80, ;
        Caption = "HelpPAMenu"
    Add Object command2 As CommandButton With ;
        Top = 93, Left = 74, Height = 27, Width = 83, ;
        Caption = "Close Form"
    Procedure command1.Click
    Public oHelpform
    do form helppamenu.scx NAME oHelpForm
Endproc

    Procedure command2.Click
    If (Vartype(oHelpform) == 'O')
        oHelpform.Release()
    Endif
    Thisform.Release()
Endproc
    Procedure Unload
    If (Vartype(oHelpform) == 'O')
        oHelpform.Release()
    Endif
Endproc
Enddefine


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
That did it..thank you very much..I can sleep again !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top