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

Closing an application problem 1

Status
Not open for further replies.

jrajesh

Programmer
Aug 12, 2001
72
HK
Hello,
This is the code in my Main Form's init event:
Code:
_SCREEN.Visible = .F.
This.Show()
READ EVENTS
CLEAR EVENTS

and this in the 'Exit' button's Click event:
Code:
nResponse=MESSAGEBOX('Do you want to quit this application?',4+32,'Confirm action')
IF nResponse=6
	CLEAR EVENTS
ELSE
	RETURN
ENDIF
THISFORM.Release
SET CLASSLIB TO
RELEASE ALL EXTENDED
RELEASE MAIN, NCOUNT, LLSPARES, LLSTORES, StoresTreeCreated
RELEASE ApplPath, GLADDMACHINERY, GLADDCOMPONENT, GLADDPART, OCONN, NRESPONSE
CLEAR PROGRAM 
CLEAR RESOURCES
RETURN

When I click the 'Exit' button the first time, the app. does not release the form and return to VFP. It only works on the second click.

I've included 'Clear Events' in 2 places because giving a 'form release' in the Exit button click event didn't work and I was trying various possibilities.

Could someone please advise where I'm going wrong?

Thanks and regards,
Rajesh
 

Could someone please advise where I'm going wrong?

I don't see QUIT anywhere in your code.


Mike Gagnon

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

The problem is that you have put READ EVENTS in the form, rather than a calling program.

It's better to write a PRG file -- a so-called main program -- to call the form. The PRG will contain this code:

Code:
_SCREEN.Visible = .F.
DO FORM MyForm
READ EVENTS

SET CLASSLIB TO
RELEASE ALL EXTENDED
RELEASE MAIN, NCOUNT, LLSPARES, LLSTORES, StoresTreeCreated
RELEASE ApplPath, GLADDMACHINERY, GLADDCOMPONENT, GLADDPART, OCONN, NRESPONSE
CLEAR PROGRAM 
CLEAR RESOURCES
RETURN

Then, in the Exit button of the form, just put:

Code:
nResponse=MESSAGEBOX('Do you want to quit this application?',4+32,'Confirm action')
IF nResponse=6
    CLEAR EVENTS
ELSE
    RETURN
ENDIF
THISFORM.Release

I think that will solve the problem.

Mike



Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Hi Mike Gagnon

The problem with QUIT is that shuts VFP right down and that makes it difficult to use from a .prg file. I typically test using DO STARTUP.PRG and build when it has passed all checks.



Jim Osieczonek
Delta Business Group, LLC
 
I'd like to Second MikeLewis's suggestion: I consider that the 'right' way to design a VFP program.

Of course, it 'kinda works' to put the READ EVENTS inside a form method, but you just found one of the difficulties... I expect there are others difficulties lurking. And, it just doesn't feel right to me, to have the event loop initiated during the .INIT or .Activate of a form.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Thank you all for your responses..

Mike Gagnon:
I don't have a quit as I need to be return to the VFP environ. on form release.

Mike Lewis:
Thanks for your advise. It works very well.
* for you.

Thanks again and regards,
Rajesh
 

I don't have a quit as I need to be return to the VFP environ. on form release.

So this will never be a compiled executable.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike Gagnon:
Your observation is right. This wouldn't be a compiled exe.

Rajesh
 
To get around the problem with VFP shutting down when running your application in the IDE as opposed to a compiled exe when using Quit, I usually use something like the following which works correctly in both situations:
Code:
IF _VFP.STARTMODE = 0
     CANCEL
ELSE
     QUIT
ENDIF

In addition to the good advice you have already gotten... One of the things about the code in your original post that bothered me was the call to Thisform.release() and then running a bunch more lines of code after that. While it will work, its not the best practice to tell something to release and then force it to stay in memory in order to run more lines of code. Thankfully VFP handles this ok, but still not the suggested method of doing it.

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
craigsboyd,
Couldn't agree with you more.
But, this piece of code was as I tried various combinations to get the 'Exit' button behaving.

Thanks though for your pointer.

Regards,
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top