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

How do I close a FORM the right way?

Status
Not open for further replies.

DJVisuaL

Programmer
May 31, 2000
52
US
Whats the proper way to create a program
with just one form? I mean starting... running the form.. and exiting..

right now I have a main program

* main.prg
******** various init code (using tables etc..)*****

DO FORM fMyForm
READ EVENTS
CLEAR EVENTS
CLOSE ALL
QUIT

and inside my form I usually have 1 exit button

* fMyForm.bExit.Click
thisform.Release

and in the destroy event
* fMyForm.Destroy
QUIT

this works fine but I think after the QUIT inside fMyForm.Destroy everything is killed at that point.. so maybe I dont need
CLEAR EVENTS
CLOSE ALL
QUIT
in main.prg???

or is there a better way all together?

thanks
DJ
 
In your main.prg you want something like...


ON KEY LABEL ALT+F4 DO quitnow
ON SHUTDOWN DO quitnow

DO FORM YourFormHere.scx

READ EVENTS && Foundation Read

PROCEDURE QuitNow
ON SHUTDOWN &&removes shutdown trap and prevents looping
QUIT &&terminates the exe
ENDIF


In your form you want a close button with...

thisform.release

 
Also do not issue CLEAR EVENTS in the same PRG with READ EVENTS. From your example you should place CLEAR EVENTS in the Form's Destroy Event. Also be aware of the Release 'gotcha.' Closing the form from the close box (and one other way I forget. New computer and no notes in front of me) fires the QueryUnload however calling Release() does not. You many want to put the following in your Release method. Perhaps even in your form class (since I'm sure you subclassed Form and the other base classes :) )
[tt]
* Thisform.Release()
IF !Thisform.QueryUnload()
* Insert your code here to inform or deal with QueryUnload returning .F.
NODEFAULT
ENDIF
[/tt]
 
Pete I tryed that and when I click the button the form goes away but I can CTRL-ALT-DELETE and see my program is still running!?
...
here is my setup..
I have a main.prg that loads a single form
the main foxpro form is hidden using config.fpw _screen off

[tab]*main.prg
[tab]ON KEY LABEL ALT+F4 DO pQuit
[tab]ON SHUTDOWN DO pQuit
[tab]*load tables etc....
[tab]DO form fMyForm
[tab]READ EVENTS
[tab]ON SHUTDOWN

[tab]PROCEDURE pQuit
[tab][tab]SELECT tMyTable && this is my only cleanup code
[tab][tab]RECALL ALL && to unmark all records for deletion from tMyTable
[tab][tab]CLEAR EVENTS
[tab][tab]CLOSE ALL
[tab][tab]QUIT
[tab]ENDPROC

[tab]*fMyForm.bExit.Click <--- my exit button
[tab]thisform.Release

OK when I click the Exit button or the X it does the same thing...
the form releases but it is still in the program list (CTRL-ALT-DELETE)
and thats the only way I can kill it

*confused*
DJ
 
Hmmm...

Are you running the form inside the screen or is it a top level form?

I'm assuming this is an EXE an not an APP...

You might try...
*fMyForm.bExit.Click <--- my exit button
CLEAR EVENTS
thisform.Release




 
Hi DJ,

DO form fMyForm
READ EVENTS

the form goes away but I can CTRL-ALT-DELETE and see my program is still running!?


My guess is fMyForm is Modal, so READ EVENTS isnt being executed until fMyForm is released and that's why the program appears to hang after the form is released. If it is modal, you don't need the READ EVENTS or you can retain the READ EVENTS and make fMyForm modeless (WindowType=0).

Are you running the form inside the screen or is it a top level form?

Again, I would assume he's running it In Screen because Top-Level's are always Modeless, and if the above mentioned was modeless, his code should execute smoothly.
 
Also, try this:

ON SHUTDOWN DO pQuit
*load tables etc....
DO form fMyForm
READ EVENTS
ON SHUTDOWN
&& Move This line

PROCEDURE pQuit
ON SHUTDOWN && To Here
SELECT tMyTable
RECALL ALL
CLEAR EVENTS
&& dont need this here
CLOSE ALL
QUIT
ENDPROC


And like Pete said:
*fMyForm.bExit.Click <--- my exit button
CLEAR EVENTS
thisform.Release
 
OK thanks guys
I haven't had time to try your suggestions yet but I will as soon as I can
...
However I did read them and to answer your questions

ShowWindow = 2 - As Top-Level Form
WindowType = 0 - Modeless

I'm kind of shady on what those mean as I am still in the learning stages but that's what I used...

DJ
 
K I moved ON SHUTDOWN into pQuit and I moved CLEAR EVENTS into the bExit button but when I pushed it I got this error on infinite loop &quot;program pquit.prg not found&quot;
...
if I pushed the X it did the same as before (form goes away but program still remains in task list)
...
looking at my code I noticed ON SHUTDOWN DO pQuit
so I changed it to ON SHUTDOWN DO pQuit IN main.prg
and this works for bExit but NOT when I push the X
so what I ended up doing is taking CLEAR EVENTS out of bExit.Click and moving it to thisform.Destroy event..
this works for both cases!

here is the code:

MAIN.PRG
-----------
*** Handle quit
[tab]ON KEY LABEL ALT+F4 DO pQuit IN cd.prg
[tab]ON SHUTDOWN DO pQuit IN cd.prg

[tab]* table init code etc..

[tab]DO FORM fMyForm
[tab]READ EVENTS

[tab]PROCEDURE pQuit
[tab][tab]ON SHUTDOWN && clear shutdown loop
[tab][tab]SELECT tMyTable
[tab][tab]RECALL ALL
[tab][tab]***CLEAR EVENTS && TOOK THIS OUT
[tab][tab]CLOSE ALL
[tab][tab]QUIT
[tab]ENDPROC

FMYFORM.SCX
-----------------
*thisform.destroy
[tab]CLEAR EVENTS

*thisform.bExit.Click
[tab]thisform.Release

how does that look?
It does work but if there is a better way I'd rather do that instead
peace
DJ
 
I once again could not found the solution. Please let me know if you have any solution for this problem. I have already send of No.of mails but till todate nothing to do.

My Problem is

My EXE runs in APP mode but not in EXE mode I mean exe build by Visual Foxpro-6 run from Command Window and not from Desktop Icon. When I run from Icon it shutdwon immediately after execution.

Please, Please help me.

Thanks
Mohammad Ahsan Rana
Lahore, Pakistan
 
Run Exe Problem (Visitor) Aug 11, 2001
I once again could not found the solution. Please let me know if you have any solution for this problem. I have already send of No.of mails but till todate nothing to do.

My Problem is

My EXE runs in APP mode but not in EXE mode I mean exe build by Visual Foxpro-6 run from Command Window and not from Desktop Icon. When I run from Icon it shutdwon immediately after execution.

Please, Please help me.

Thanks
Mohammad Ahsan Rana
Lahore, Pakistan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top