Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ON SHUTDOWN
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Titre:
Divers
Thread ID:
00304282
Message ID:
00304877
Vues:
33
Hi Erik,

I understand your concern -- however, I chose to handle it in the original "style" in which Stacy had written her code, hopefully to help her understand it a bit more.

In my apps, I don't use that particular technique either.

BTW -- good picture change (g).

>>That did it! Thank you Evan, you made my day better.
>>
>>Stacy
>
>Stacy, Evan, Victor-
>
>Very often, people make this much more difficult than it needs to be. There is no need for an ON SHUTDOWN routine, you only need to have ON SHUTDOWN CLEAR EVENTS
>
>Then your main program should do something like:
>
>ON SHUTDOWN CLEAR EVENTS
>DO FORM MyMainForm
>READ EVENTS
>
>You never need to issue a QUIT, or anything else, for that matter (unless you have outstanding object references, you'll want to issue a CLEAR ALL). The code will run right through, and your application will unload itself, releasing all variables and closing all tables. Then all you need is your exit menu to issue a CLEAR EVENTS, and all close methods will run the same exact code.
>
>Generally, a good framework will have the power to veto the shutdown if any form doesn't want to close.
>
>I do this in my framework with a READ EVENTS loop. My simplified code looks like this in the main program:
>
>DO WHILE .T.
> READ EVENTS
> IF Cleanup()
> EXIT
> ENDIF
>ENDDO
>
>Cleanup is a routine that loops through all open forms and asks them to close, gigin them the power to refuse:
>
>FOR EACH oForm IN _screen.Forms
> IF TYPE("oForm.Name") = "C"
> * Toolbar
> IF UPPER(oForm.BaseClass) <> "TOOLBAR"
> IF oForm.QueryUnload()
> oForm.Release()
> ELSE
> RETURN .F.
> ENDIF
> ENDIF
> ENDIF
>ENDFOR
>
>If any form refuses to close, Cleanup returns .F., and the program reenters the wait state initiated by CLEAR EVENTS. In real life, cleanup does some other stuff too, but this is mostly environment restoration for use when I run the main prg in interactive mode. (I can do this, because my code NEVER uses QUIT- there is absolutely no need for it.)
>
>This strategy may seem a little strange at first, but it works beautifully in all situations, and allows you write cleanup code in one place. I highly recommend that you learn exactly what happens in the flow of things in your programs, because sooner or later, you'll get caught with a problem that stemmed from you not knowing what was REALLY happening...
Evan Pauley, MCP
Positronic Technology Systems LLC
Knoxville, TN

If a vegetarian eats vegetables, what does a humanitarian eat?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform