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

problem with releasing forms 2

Status
Not open for further replies.

R17

Programmer
Jan 20, 2003
267
PH

i have form2 that shows on top of form1. if my user clicks the "ok" button in form2, i want form1 and form2 to be released and show form3.

i have this,

Code:
thisform.release
_screen.activeform.release
if _screen.activeform.caption="form1"
	messagebox ("form1")
endif
if _screen.activeform.caption="form2"
	messagebox ("form2")
endif
do form form3

thisform.release is supposed to release form2 and _screen.activeform.release is supposed to release form1. the code that follows is only to check what form is still active.

why am i getting the messagebox form2 instead of do form form3?
 
I suspect form2 is a modal form, and if so, try the following:

* this would be from form 1

DO FORM FORM2 TO llCloseAll
IF llCloseAll = .T.
THISFORM.RELEASE
ENDIF


On FORM2.
1. Create a property, I'll call mine closeall. By default it will be set to .F.
2. In the CLOSE button click event - place the following code:

THISFORM.closeAll = .T.
THISFORM.RELEASE

3. In the UNLOAD event of form2 place the following code:
RETURN THISFORM.CloseAll


When form2 closes it will pass a value to form1. Form1 will then close if the .t. / .f. value is .t.


Jim Osieczonek
Delta Business Group, LLC
 
Try this one.

1. In your Form2 INIT event, put DO FORM Form1.

2. Following will the code in your OK button.

thisform.release
if ThisForm.Name="Form1"
messagebox ("form1")
Form1.release()
endif
do form form3



Gene
 
Try this one.

1. In your Form2 INIT event, put DO FORM Form1.

2. Following will be the code in your OK button.

thisform.release
if ThisForm.Name="Form1"
messagebox ("form1")
Form1.release()
endif
do form form3



Gene
 
Hi

If you call the forms with name class.. example..

DO FORM form1 NAME form1 LINKED
DO FORM form2 Name form2 LINKED

Then, in the OK button of form2..

Form1.Release()
Form2.Release()
DO FORM form3 NAME form3 LINKED

This should work. :)


____________________________________________
Ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 

hi ramani,

form1 is set "as main". how can i do that? is there a need for me to have a main.prg then call the form with "name"?
 
R17

'is there a need for me to have a main.prg then call the form with "name"?'

Yes - if you launch your form from the root of main.prg, the name oMain becomes PUBLIC by default as thus will never go out of scope, ie

DO FORM main NAME oMain LINKED

If you use the name clause elsewhere in your application, there is a risk it may go out of scope depending on where you call the form.

To prevent this happening put :-

PUBLIC oForm2
DO FORM form2 NAME oForm2 LINKED

and put

RELEASE oForm2

in the the .UnLoad() event of form2 to prevent dangling object references.

Prefixing the name with 'o' identifies to a developer an object reference.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 

thanks ramani and chris!
 


hi chris,

i have do form dtr name omain linked in my main prg and the following code in ok button of my form3.
Code:
case thisform.opgreportoutput.value=1
    thisform.hide()
    oform = _screen.activeform
    omain.hide()
    oform.hide()
    set classlib to prev additive
    opreviewfrm=createobject("PrintPreview")
    release classlib prev
    keyboard "{ctrl+f10}"
    report form &creport environment noconsole preview in window printpreview
    opreviewfrm=.null.
    omain.show()
    oform.show()
    thisform.show()

when i run my application, the printpreview and all other forms does not show (it seemed like i've unloaded all forms).

what's wrong with the code?

 


i still can't get this working. any more help pls?

 
Hi R17,

Just try this code..


case thisform.opgreportoutput.value=1
thisform.hide()
oform = _screen.activeform
omain.hide()
oform.hide()

** set classlib to prev additive
** opreviewfrm=createobject("PrintPreview")
** release classlib prev
** keyboard "{ctrl+f10}"
** report form &creport environment noconsole ;
** preview in window printpreview
** opreviewfrm=.null.
*************************************
** if you are using TopLevel form with
** _screen.Visible = .f.
** Then... change the _screen.Visible = t.
oRepForm = CREATEOBJECT("FORM")
WITH oRepForm
.Caption = "Report Window"
.WindowState = 2
.Show()
ENDWITH
REPORT FORM (cReport) PREVIEW WINDOW ;
(oRepForm.Name) TO PRINTER PROMPT
oRepForm.Release()
RELEASE oRepForm
** change back _screen.Visible to your requirement.
** Then your code...
omain.show()
oform.show()
thisform.show()

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 


i'm hopeless.. =( i use this code in other forms and it works perfectly fine. i don't know what else to do.

here,

in my main form (dtr), i have a submenu that calls form2. this form2 has a print button that calls form3. form3 has an ok button which when clicked should hide form2, form3 and dtr. so that only my printpreview form is shown. but when i run, dtr is shown on top of printpreview although dtr is not clickable (clicking the close button of the printpreview closes itself and dtr)

in dtr, i have another submenu that calls form3 (the same form called by form2). when the ok button of form3 is clicked, form3 and dtr is hidden and printpreview is shown.

pls help..
 


hi everyone,

i tried releasing form2 before calling form3. i changed form3 to modeless and everything worked fine.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top