Article ID: 130306
Article Last Modified on 2/10/2000
* Begin code example
* Save This as CSET.PRG
* This class provides SET environment save/SET/restore capabilities
* When the class is instantiated, the current SET environment is
* saved & SET to the desired value. When the instantiated object goes
* out of scope, the environment is restored.
* Usage:
* CreateObject( "CSET", <cExpr1>, <cExpr2> | <nExpr2> [, <cExpr3>] )
*
* cExpr1 = One of the SET commands
* cExpr2 = Appropriate character value for the SET command
* nExpr2 = Appropriate numeric value for the SET command
* cExpr3 = Optional character value for SET commands that are both
* ON | OFF
* and have another value (like ALTERNATE, FIELDS, etc.)
*
* Examples:
* loDeletedSave = createobject( "CSET", "deleted", "on" )
* loDecimalsSave = createobject( "CSET", "decimals", 5 )
* loAlternateSave = createobject( "CSET", "alternate", "on", ;
* "alter.txt")
DEFINE CLASS CSET AS CUSTOM
* PROTECTED Data Members
* =====================================================
PROTECTED mcSET && SET command
PROTECTED muOrgValue && Original value of the SET
PROTECTED muOrgValue1 && Original secondary value of the SET
* Public Data Members
* ========================================================
* NONE
* PROTECTED Function Members
* =================================================
* Constructor Method
* ----------------------------------------------------------
PROTECTED FUNCTION Init
PARAMETER pcSET, puNewValue, pcNewValue1
LOCAL lnParmCount && number of PARAMETERs sent to init
LOCAL lcSETCommand && constructed SET command
lnParmCount = PARAMETERS()
* Default the data members
This.mcSET = ""
This.muOrgValue = ""
This.muOrgValue1 = ""
IF ( lnParmCount < 2 )
* This.error( "some error" )
RETURN
ENDIF
* Save current environment
This.mcSET = pcSET
This.muOrgValue = SET( pcSET )
This.muOrgValue1 = SET( pcSET, 1 )
IF ( This.muOrgValue == This.muOrgValue1 )
* throw This away because we don't need it
This.muOrgValue1 = ""
ENDIF
IF ( lnParmCount = 3 )
* optional argument handling
lcSETCommand = pcSET + " to " + pcNewValue1
SET &lcSETCommand
ENDIF
IF ( TYPE( "This.muOrgValue" ) == 'C' )
* character type of SET
lcSETCommand = puNewValue
IF ( ! INLIST( This.muOrgValue, "ON", "OFF" ) )
* not a simple ON|OFF so add a TO keyword
lcSETCommand = "TO " + puNewValue
ENDIF
ELSE
* numeric type of SET
lcSETCommand = "TO " + STR( puNewValue )
ENDIF
lcSETCommand = pcSET + " " + lcSETCommand
SET &lcSETCommand && change the SET
* Destructor Method
* ---------------------------------------------------- ------
PROTECTED function Destroy
*LOCAL lcSETCommand && constructed SET command
IF ( EMPTY( This.mcSET ) )
RETURN
ENDIF
IF ( TYPE( "This.muOrgValue" ) == 'C' )
* character type of SET
lcSETCommand = This.muOrgValue
IF ( ! INLIST( This.muOrgValue, "ON", "OFF" ) )
* not a simple ON|OFF so add a TO keyword
lcSETCommand = "TO " + This.muOrgValue
ENDIF
ELSE
* numeric type of SET
lcSETCommand = "TO " + STR( This.muOrgValue )
ENDIF
lcSETCommand = This.mcSET + " " + lcSETCommand
SET &lcSETCommand && restore the SET
IF ( ! EMPTY( This.muOrgValue1 ) )
* restore secondary SET information
lcSETCommand = This.mcSET + " TO " + This.muOrgValue1
SET &lcSETCommand
ENDIF
* Public Function Members
* ====================================================
* Value Method
* ---------------------------------------------------------------
* RETURN the current values of the PROTECTED data members in a comma
* delimited string.
FUNCTION Value
LOCAL lcRETURNValue
IF ( TYPE( "This.muOrgValue" ) == 'C' )
lcRETURNValue = This.mcSET + "," + This.muOrgValue
ELSE
lcRETURNValue = This.mcSET + "," + ;
ALLTRIM( STR( This.muOrgValue ) )
ENDIF
IF ( ! EMPTY( This.muOrgValue1 ) )
lcRETURNValue = lcRETURNValue + "," + This.muOrgValue1
ENDIF
RETURN lcRETURNValue
ENDDEFINE
*** END CODE EXAMPLE FOR cSET.PRG
******************************************************************
*Begin code example
******************************************************************
* Driver program to test CSET class
SET PROCEDURE TO cset ADDITIVE
CLEAR
SET DELETED ON && start it out on for testing
_Screen.Show
? "Deleted:", SET("deleted")
loDeletedSave = CreateObject( "CSET", "deleted", "off" )
? "Value:", loDeletedSave.Value()
? "Deleted:", SET("deleted")
Deleted: ON Value: deleted, ON Deleted: OFF
Additional query words: VFoxWin
Keywords: kbcode KB130306