Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Quit an Application
Message
From
12/01/2003 11:58:09
Charlie Schreiner
Myers and Stauffer Consulting
Topeka, Kansas, United States
 
 
To
11/01/2003 15:57:08
John Tomblin
Service Station Systems, Inc.
San Jose, California, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00740696
Message ID:
00740795
Views:
24
Hi John,
I think exiting an application where errors have occurred is hard. I use an application object and try to ensure that it can always be released cleanly. I don't ever use QUIT, CLOSE ALL, CLEAR ALL, CANCEL in my code. The error handler categorizes errors and sets a ThisApp.ShutDownApp property when it's appropriate. Methods return .F. when we are unsuccessful. Once the ShutDownApp property is .F., the ErrorHandler doesn't show anymore dialogs. I suggest you organize the startup tasks you mentioned into methods. Here's what my Application object's Init looks like. BTW, several main handlers are on the application--that's why you don't see them in the Init(), but it could be otherwise. Only if the startup tasks are successful does the READ EVENTS get issued. Once it does, the application knows how to CLEAR EVENTS and the objects destroy as they go out of scope.
LPARAMETER IniFileName
IF VARTYPE(m.IniFileName) = "C" AND NOT EMPTY(m.IniFileName)
   This.IniFileName = m.IniFileName
ENDIF
LOCAL EveryThingOK
EverythingOK = .F.	&& Prove this wrong.
IF NOT THIS.AllowMultipleInstances 
   IF NOT THIS.CheckForMultipleInstances()  && If this method returns .F., there is 
      This.Destroy()   && Destroy doesn't run automatically if the init doesn't 
      RETURN m.EveryThingOK && another copy of this app running. This method
   ENDIF   && will bring it forward.
ENDIF
* If any of these methods fail, it should return false and we
* should quit.  The safest technique is to use a CASE statement
* so if any one thing fails, we don't compound the problem be continuing.
WITH This
   DO CASE
   CASE .ShutDownApp  && Something bad has already occurred.
   CASE NOT .PropertiesOK()   && This means the PropertyHandler has done it's thing.
   CASE NOT .CheckBackup() && During backup time, you can't get in.
   CASE NOT .CheckEnableLogin() AND NOT .AdviseInit() && Determine if Login is allowed.
   CASE NOT .Login()        && Is the user allowed in?
   CASE NOT .Requery()      && This sets up locking and additional user info.
   CASE NOT .SetCaption()
   CASE NOT .CreateoSplashScreen() && This is where the _SCREEN.Visible = .T.!
   CASE NOT .SetStatus()    && Allows you to show progress or status.
   CASE NOT .SetDblClick()  && Set the DblClick speed equal to the windows setting.
   CASE NOT .CreateoMemory()
   CASE NOT .OpenTables()   && Open commonly used tables, if desired.
   CASE NOT .CreateoSecurity()	
   CASE NOT .CreateoRules()
   CASE NOT .CreateoReports() && Report object
   CASE NOT .SetUpHelp()
   CASE NOT .Refresh(.T.)
   CASE NOT .DefaultAction()
   CASE NOT .You get the idea....()
   OTHERWISE
      EveryThingOK = .T.
      *When a user wishes to leave Windows and the application is still running
      *what should happen?
      ON SHUTDOWN IIF(VARTYPE(ThisApp)=="O",ThisApp.Release(.T.,.F.,.T.), ;
           _SCREEN.Forms[2].Release())
      * IIF is so if the develop runs the app twice, we can still get released via 
      * the Forms collection. (ThisApp may be gone!)
      * Parameter1 is Force, 
      * Parameter2 is FromQueryUnload
      * Parameter3 is FromShutDown-- this helps resolve the situation when Release is called.
   ENDCASE
   IF NOT m.EveryThingOK 
      .CallStackReleased = .T. && This keeps the Timer in the release from being created. 
                               && We don't need it here.
      .Release()
      .Destroy()   && Destroy doesn't run automatically if the init doesn't 
   ENDIF           && complete with success.
ENDWITH
RETURN m.EverythingOK
>Like most applications, I begin with a prg that displays a splash screen, sets up the environment, opens the database, checks the user's permissions, and finally calls the menu.
>
>Before the database is opened, I issue the following command:
> on error do GiveUp
> open database MyData shared
>
> *------------------------------------------------
> procedure GiveUp
>
> =MessageBox("Helpful Hints ...")
> close all
> clear all
> quit
> cancel
> return
>
>All I want to do is to display a message and terminate.When the database cannot be opened, the messagebox does appear but, the application continues to run and produce error after error. Also, making this a function and returning .F. won't work either.
>
>Is it possible to force the termination of an application. If so. How?
Charlie
Previous
Reply
Map
View

Click here to load this message in the networking platform