Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error Handling (Shutdown problem)
Message
De
05/10/2000 09:51:54
 
 
À
05/10/2000 09:09:03
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00425207
Message ID:
00425280
Vues:
17
>Code such as this may help you exit more gracefully. Seems like the easy things got much more difficult in windows:
>
>* attempt to clean up environment
>LOCAL numforms,i,x,tcontrols,demembers,toselect,looped
>numforms=_screen.formcount
>looped=0
>on shutdown
>do while .t.
>	for i=1 to numforms	
>	if type('_screen.forms[i]')='O'
>		* need code here to check dataenvironment
>		* and close tables reverting them as necessary
>		IF !ISNULL(_screen.forms[i])
>		* first, is this form using a private data environment?
>		* assumes all forms are using data buffering
>		SET DATASESSION TO _screen.forms[i].datasessionid
>		if _screen.forms[i].datasession=2	&& is private	
>		   if type('_screen.forms[i].dataenvironment')<>'O'
>			loop					
>		   endif
>		   release demembers
>		   dimension demembers[1]
>		   =amembers(demembers,_screen.forms[i].dataenvironment,2)
>		   if vartype(demembers)='L'
>			_screen.forms[i].visible=.f.
>			_screen.forms[i].release()				
>			loop
>		   endif
>		   tcontrols= alen(demembers,1)				
>		   for x=1 to tcontrols				
>			* is it a cursor, table, relation
>			* check for readonly to keep from writing over changes  to tables like company etc when it is not intended.
>			if upper(_screen.forms[i].dataenvironment.&demembers    [x]..class)='CURSOR' AND ;
>			!_screen.forms[i].dataenvironment.&demembers[x]..readonly=.t.
>			toselect= _screen.forms[i].dataenvironment.&demembers[x]..alias
>							if used(toselect)
>								select (toselect)					
>								if cursorgetprop('buffering')>1
>									* is it row or table buffering doesn't matter
>									=tablerevert(.t.)
>								endif
>							endif
>						endif
>					next
>					* close the tables - this is done by the form release method.				
>				endif
>				_screen.forms[i].visible=.f.
>				_screen.forms[i].release()							
>			ENDIF
>		endif	
>	next
>	looped=looped+1
>	numforms = _screen.formcount
>	if numforms= 0 or looped=3
>		exit
>	endif
>enddo
>on shutdown
>on error do X_nothin
>this.quitloop=.t.
>clear events
>return to main
>* this is form development environment
>set sysmenu to default
>set datasession to 1
>close tables all
>*!*	clear all
>*!*	clear all
>*!*	clear all
>ON ERROR
You should know that this code will only iterate through every other form because VFP rearranges the indexes in the form collection every time a form is released.

Secondly, while very thorough, this code could be much simpler if the responsibility for checking data and updating from the controlsource were left up to the form. IOW, this type of thing should be handled in a form class, and not in the shutdown routine.

Just my .02
Erik Moore
Clientelligence
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform