Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Graceful exit on ESC from triggers and rules
Message
 
 
À
07/04/2005 17:07:48
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01002344
Message ID:
01002602
Vues:
16
>the class definition MUST be in a separate but accessable procedure, such as a separate procedure in the database stored procedures. I would base the class on Custom or Relation because we need this class to participate in the current datasession.
>
>You may want to design this class in one of your Classlibraries because this technique can be generalized and subclassed as necessary as a state restorer class. (Memento pattern)
>
>Glenn

Glenn,

This idea works good, thanks. The only problem is the overhead. Say, now I save all settings and restore them all (I subclassed cSessionEnvironment class from MereMortals for that purpose). I want to only restore the ones I changed. I can compare the old settings with the new, but still it would be too much code to execute. My trigger's code is already quite slow...
**************************************************
*-- Class:        asessionenvironment (c:\mmviscollect\libs\aenviron.vcx)
*-- ParentClass:  csessionenvironment (c:\mmortals\common30\libs\cenviron.vcx)
*-- BaseClass:    container
*-- Time Stamp:   04/08/05 09:57:02 AM
*
DEFINE CLASS asessionenvironment AS csessionenvironment


	*-- Saves on('error')
	conerror = ""
	*-- Saves on('escape')
	conescape = ""
	Name = "asessionenvironment"
	CLabel1.Caption = "aSessionEnvironment"
	CLabel1.Name = "CLabel1"

	*-- Saves the originally used tables
	DIMENSION aoriginallyused[1]


	PROCEDURE saveoldsettings
		DODEFAULT()
		=AUSED(this.aOriginallyused) 
		this.cOnError = ON('error')
		this.cOnEscape = ON('escape')
	ENDPROC


	PROCEDURE Init
		*---------------------- Location Section ------------------------
		*   Library: 	Aenviron.vcx
		*   Class: 		Asessionenvironment  
		*   Method: 	Init() 
		*----------------------- Usage Section --------------------------
		*)  Description: 
		*)

		*   Scope:      Public
		*   Parameters: 
		*$  Usage:      
		*$              
		*   Returns:  
		*--------------------- Maintenance Section ----------------------
		*   Change Log:
		*       CREATED 	04/08/2005 - NN 
		*		MODIFIED
		*----------------------------------------------------------------
		*-- Save the original values of the settings if 
		*-- specified to
		IF This.lSaveOldSettings
			This.SaveOldSettings()
		ENDIF
		THIS.cOldDatabase = SET('DATABASE')
	ENDPROC


	PROCEDURE Destroy
		*---------------------- Location Section ------------------------
		*   Library: 	Aenviron.vcx
		*   Class: 		Asessionenvironment  
		*   Method: 	Destroy() 
		*----------------------- Usage Section --------------------------
		*)  Description: 
		*)

		*   Scope:      Public
		*   Parameters: 
		*$  Usage:      
		*$              
		*   Returns:  
		*--------------------- Maintenance Section ----------------------
		*   Change Log:
		*       CREATED 	04/08/2005 - NN 
		*		MODIFIED
		*----------------------------------------------------------------
		DO WHILE TXNLEVEL( )> 0
		   ROLLBACK
		ENDDO

		IF This.lSaveOldSettings
		  This.Reset()
		ENDIF


		   
	ENDPROC


	PROCEDURE reset
		*---------------------- Location Section ------------------------
		*   Library: 	Aenviron.vcx
		*   Class: 		Asessionenvironment
		*   Method: 	Reset()
		*----------------------- Usage Section --------------------------
		*)  Description:
		*)

		*   Scope:      Public
		*   Parameters:
		*$  Usage:
		*$
		*   Returns:
		*--------------------- Maintenance Section ----------------------
		*   Change Log:
		*       CREATED 	04/08/2005 - NN
		*		MODIFIED
		*----------------------------------------------------------------
		*---------------------- Location Section ------------------------
		*   Library: CEnviron.vcx
		*   Class:   CSessionEnvironment
		*   Method:  Reset()
		*----------------------- Usage Section --------------------------
		*)  Description:
		*)		Resets the original value of all VFP SET Commands
		*)		that are scoped to the local data session

		*   Scope:      Public
		*   Parameters: None
		*$  Usage:
		*$
		*   Returns:  Logical .T. by default
		*--------------------- Maintenance Section ----------------------
		*   Change Log:
		*       CREATED
		*		MODIFIED
		******************************************************************
		dodefault()
		local lcPrev, lnI, lcTable, lnTables, laTables[1]
		lcPrev = this.cOnError
		on error &lcPrev
		lcPrev = this.cOnEscape
		on escape &lcPrev
		lnTables = aused(laTables)
		for lnI = 1 to m.lnTables
			lcTable = laTables[m.lnI, 1]
			if not empty(m.lcTable) and ascan(this.aOriginallyUsed , m.lcTable) = 0
				use in (m.lcTable)
			endif not empty(lcTable) ...
		next lnI
	ENDPROC


ENDDEFINE
*
*-- EndDefine: asessionenvironment
**************************************************
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform