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

ON SHUTDOWN errs "File 'onmenuexit.prg' not found" 2

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,

I have a procedure OnMenuExit in my Main.PRG, called off my bar menu (File/Exit), that closes all the open forms, files, tables, classlibs, etc. - U know what I mean.
In order for my end users to close the EXE by clicking on the main screen's X button (I use VFP's _SCREEN as MDI container), I have to have

ON SHUTDOWN DO OnMenuExit()

So, I put it into the main proc before READ EVENTS, compiled my EXE, ran it, clicked on that X - and got that error message in subject.

I tried

ON SHUTDOWN DO OnMenuExit

ON SHUTDOWN =OnMenuExit()

ON SHUTDOWN OnMenuExit

ON SHUTDOWN OnMenuExit()

and the result always was that same one...

Any idea how to fix this discrepancy?

TIA!

Regards,

Ilya
 
Do ON SHUTDOWN CLEAR EVENTS or ON SHUTDOWN QUIT.

Even without a cleanup routine all forms queryunload events will run etc. you can react there to do things you do in your exit routine, it's absolutly not needed.

There are situations like being in a print preview and clicking _screens or top form's quit X button, in which you'll get that error, the only reliable thing you can always call is the method of a global object, eg goApp.onexit(), but I'd rather not use a cleanup routine anymore anyway.

Even if you simply do On Shutdown Quit there are a whole lot of events of al objects running and each can have it's individual cleanup.

Bye, Olaf.
 
Ilya,

Unlike the others, I think your approach is basically correct - at least, as far as I can judge based on the information you have given.

It's more likely that the error occurred because VFP couldn't find OnMenuExit for some reason - perhaps it's not present in the main program, or it is not properly defined, or something similar. I suggest you check those points before you do anything else.

One other point: the shutdown routine should itself contain ON SHUTDOWN (by itself).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Indeed I tested my assumption and I'm wrong in that the routine itself is also available during a print preview. Iget another unwanted behavior though, that a click on the _Screen's X button is only quitting the print preview and not foxpro, when you do this:

Code:
On Shutdown onexit()
Report Form Home()+"Tools\FileSpec\90FRX.FRX" Preview

Procedure onexit() 
   Wait Window 'Bye' Timeout 1
   On Shutdown
   Quit

And the report preview also consumes the Quit if you simply do
Code:
On Shutdown Quit
Report Form Home()+"Tools\FileSpec\90FRX.FRX" Preview

And then click _Screen's X during report preview.

That's a bit spooky. I still stand with an exit procedure rather being unneded, if all your classes are tidying up in their queryunload or destray event anyway.

You don't need to cancel you don't need to close databases all, close all, release all etc. all this is done by the shutdown of the vfp runtime anyway.

Bye, Olaf.
 
Thank you, Olaf!
ON SHUTDOWN QUIT did work.


Regards,

Ilya
 
I think ON SHUTDOWN QUIT is a risky way to go. Your original problem was that you have ONMENUEXIT in a procedure file instead of standing alone. Either use DO .. IN or (my preference) put the routine into a PRG.

Tamar
 
And what exactly the danger of ON SHUTDOWN QUIT would be, Tamar? (FYI, I put it into IF !glDevelop//ON SHUTDOWN QUIT//ENDIF construct, so it's in effect only when it's EXE run, not in the VFP's IDE).

Regards,

Ilya
 
I'm interested in an answer too.

While we're waiting for that let me put two things straight on CLEAR EVENTS and QUIT.

There are two beliefs about these, which aren't true:

1. CLEAR EVENTS immediately returns to the line after READ EVENTS

No it does not, only after the call stack has been done, the CLEAR EVENTS clears the READ EVENTS, eg code directly following CLEAR EVENTS is still run.

2. QUIT immediatly quits foxpro.

No, QUIT jsut starts to exit and triggers all Destroy() events for example, you can still tidy up in all forms etc.

To demonstrate both run this as a prg:

Code:
o = CreateObject("myForm")
o.Show()
Read Events

Define Class myForm as Form
   Add Object Quit As CommandButton
   
   Procedure Quit.click()
      Quit
   EndProc 
   
   Procedure Destroy()
      Clear Events
      Activate Screen
      ? 'Bye'
      MessageBox("Bye")
   EndProc 
EndDefine

Both by quitting the Form with the Quit Button or via the standard X close button on the top right form corner, you get a Bye on _screen and as Messagebox.

Bye, Olaf.
 
This is quite interesting observation, colleague Olaf!
I have it known for quite a while that the statement "When CLEAR EVENTS is executed, program execution continues on the program line immediately following READ EVENTS" in VFP's Help is incorrect (and has been since VFP3 at least.) I just did not know the sequence of events happening after CLEAR EVENTS. I do now, thanks to you!

Regards,

Ilya
 
The problem with QUIT, in my view, is that you don't end up running the clean-up code of the main program.

Tamar
 
Yes, Tamar, that's what I thought your answer would be.

However! ;-)

I, actually, found the solution (truth to be said, someone, on one of the 3 forums I am a member of, pointed me out):

ON SHUTDOWN DO OnShutDown IN My_Main.PRG

- and I can't remember who it was and/or on which forum...
But the issue's been resolved.

Thank y'al, colleagues!

Regards,

Ilya
 
It was me farther up this thread. I said to either use DO ... IN or put the routine in a separate PRG.

Tamar
 
Knowing you can do cleanup in the individual objects, forms etc you don't need some general cleanup code in th main.prg actually.

That type of last cleanup could be in the goApp.Destroy() event, eg closing all (foxpro) transactions.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top