*!* this is a cleanup class that can be used in a procedure to automatically *!* return set settings to the state that they were in when it was called *!* Declare a local variable to contain the object reference to the save settings instance *!* use newobject to create the savesettings object *!* on exit from the procedure, the variable goes out of scope and executes the destroy event *!* which automatically resets any settings to the value they were on entry. *!* pass 1 parameter (or more) (any data type) and it will save and restore workarea settings, including index order and record pointer unless parameter 2 or 3 are = .t. *!* pass parameter 2 = .t. and it does not return to the same index order on exit - default = .f. *!* pass parameter 3 = .t. and it does not return to the same record number on exit - default = .f. *!* example to save and restore settings only *!* local m.loCleanupObj *!* m.loCleanupObj = NEWOBJECT("savesettings","savesettings.fxp","",.t.) *!* example to save and restore settings and work area settings (select(), index, and recno()) *!* local m.loCleanupObj *!* m.loCleanupObj = NEWOBJECT("savesettings","savesettings.fxp","",.t.) Define Class SaveSettings as Custom Protected aSetStatus[106] Protected lReturnWorkAreaSettings lReturnWorkAreaSettings = .f. Protected nCurrentWorkArea nCurrentWorkArea = select() Protected cCurrentAlias cCurrentAlias = alias() Protected lReturn2IndexOrder lReturn2IndexOrder = .t. Protected nCurrentIndexNum nCurrentIndexNum = val(sys(21)) Protected cCurrentIndexOrder cCurrentIndexOrder = set("order") Protected lReturn2Recno lReturn2Recno = .t. Protected nCurrentRecno nCurrentRecno = recno() Procedure Init() parameters lSaveWorkAreaInfo,lNoReturn2Index,lNoReturn2Recno this.nCurrentWorkArea = select() this.cCurrentAlias = alias() this.nCurrentIndexNum = val(sys(21)) this.cCurrentIndexOrder = set("order") this.nCurrentRecno = recno(select()) if pcount() > 0 this.lReturnWorkAreaSettings = .t. if pcount() > 1 this.lReturn2IndexOrder = iif(type("lNoReturn2Index") = "L",!lNoReturn2Index,.t.) endif if pcount() > 2 this.lReturn2Recno = iif(type("lNoReturn2Recno") = "L",!lNoReturn2Recno,.t.) endif else this.lReturnWorkAreaSettings = .f. endif dimension this.aSetStatus[106] this.aSetStatus[1] = "SET ALTERNATE TO "+this.force2str(SET("ALTERNATE",1)) this.aSetStatus[2] = "SET ALTERNATE "+this.force2str(SET("ALTERNATE")) this.aSetStatus[3] = "SET ANSI "+this.force2str(SET("ANSI")) this.aSetStatus[4] = "SET ASSERTS "+this.force2str(SET("ASSERTS")) this.aSetStatus[5] = "SET AUTOSAVE "+this.force2str(SET("AUTOSAVE")) this.aSetStatus[6] = "SET BELL "+this.force2str(SET("BELL")) this.aSetStatus[7] = "SET BELL TO "+'"'+this.force2str(SET("BELL",1))+'"' this.aSetStatus[8] = "SET BLOCKSIZE TO "+this.force2str(SET("BLOCKSIZE")) this.aSetStatus[9] = "SET BRSTATUS "+this.force2str(SET("BRSTATUS")) this.aSetStatus[10] = "SET CARRY "+this.force2str(SET("CARRY")) this.aSetStatus[11] = "SET CENTURY "+this.force2str(SET("CENTURY")) this.aSetStatus[12] = "SET CENTURY TO "+this.force2str(SET("CENTURY",1))+" ROLLOVER "+this.force2str(SET("CENTURY",2)) this.aSetStatus[13] = "SET CLEAR "+this.force2str(SET("CLEAR")) this.aSetStatus[14] = "SET CLOCK "+this.force2str(SET("CLOCK")) this.aSetStatus[15] = "SET COMPATIBLE "+this.force2str(SET("COMPATIBLE"))+" "+this.force2str(SET("COMPATIBLE", 1)) this.aSetStatus[16] = "SET CONFIRM "+this.force2str(SET("CONFIRM")) this.aSetStatus[17] = "SET CONSOLE "+this.force2str(SET("CONSOLE")) this.aSetStatus[18] = "SET COVERAGE TO "+IIF(!EMPTY(SET("COVERAGE")),'"'+this.force2str(SET("COVERAGE"))+'"'+" ADDITIVE" ,"") this.aSetStatus[19] = "SET CPCOMPILE TO "+this.force2str(SET("CPCOMPILE")) this.aSetStatus[20] = "SET CPDIALOG "+this.force2str(SET("CPDIALOG")) this.aSetStatus[21] = "SET CURRENCY "+this.force2str(SET("CURRENCY")) this.aSetStatus[22] = "SET CURRENCY TO "+this.force2str(SET("CURRENCY",1)) this.aSetStatus[23] = "SET CURSOR "+this.force2str(SET("CURSOR")) this.aSetStatus[24] = "SET DATABASE TO "+IIF(!EMPTY(dbc()),'"'+dbc()+'"' ,"") this.aSetStatus[25] = "SET DATASESSION TO "+this.force2str(SET("DATASESSION")) this.aSetStatus[26] = "SET DATE TO "+this.force2str(SET("DATE")) this.aSetStatus[27] = "SET DEBUG "+this.force2str(SET("DEBUG")) this.aSetStatus[28] = "SET DECIMALS TO "+this.force2str(SET("DECIMALS")) this.aSetStatus[29] = "SET DEFAULT TO '"+this.force2str(addbs(sys(5)+sys(2003)))+"'" this.aSetStatus[30] = "SET DELETE "+this.force2str(SET("DELETED")) this.aSetStatus[31] = "SET DELIMITERS TO "+'"'+this.force2str(SET("DELIMITERS", 1))+'"' this.aSetStatus[32] = "SET DELIMITERS "+this.force2str(SET("DELIMITERS")) this.aSetStatus[33] = "SET DEVELOPMENT " +this.force2str(SET("DEVELOPMENT")) this.aSetStatus[34] = "SET DEVICE TO " +this.force2str(SET("DEVICE")) this.aSetStatus[35] = "SET ESCAPE " +this.force2str(SET("ESCAPE")) this.aSetStatus[36] = "SET EXACT " +this.force2str(SET("EXACT")) this.aSetStatus[37] = "SET EXCLUSIVE " +this.force2str(SET("EXCLUSIVE")) this.aSetStatus[38] = "SET EVENTTRACKING "+this.force2str(SET("EVENTTRACKING")) this.aSetStatus[39] = "SET EVENTTRACKING TO "+IIF(!EMPTY(SET("EVENTTRACKING", 1)),'"'+this.force2str(SET("EVENTTRACKING", 1))+'"',"") this.aSetStatus[40] = "SET FDOW TO " +this.force2str(SET("FDOW")) this.aSetStatus[41] = "SET FIXED " +this.force2str(SET("FIXED")) this.aSetStatus[42] = "SET FULLPATH " +this.force2str(SET("FULLPATH")) this.aSetStatus[43] = "SET FWEEK TO " +this.force2str(SET("FWEEK")) this.aSetStatus[44] = "SET HEADING " +this.force2str(SET("HEADING")) this.aSetStatus[45] = "SET HELP " +this.force2str(SET("HELP")) this.aSetStatus[46] = "SET HELP TO "+'"'+this.force2str(SET("HELP",1))+'"' this.aSetStatus[47] = "SET HOURS TO " +this.force2str(SET("HOURS")) this.aSetStatus[48] = "SET INTENSITY " +this.force2str(SET("INTENSITY")) this.aSetStatus[49] = "SET KEYCOMP TO " +this.force2str(SET("KEYCOMP")) this.aSetStatus[50] = "SET LIBRARY TO " +this.force2str(SET("LIBRARY")) this.aSetStatus[51] = "SET LOCK " +this.force2str(SET("LOCK")) this.aSetStatus[52] = "SET LOGERRORS " +this.force2str(SET("LOGERRORS")) this.aSetStatus[53] = "SET MARGIN TO " +this.force2str(SET("MARGIN")) this.aSetStatus[54] = "SET MARK TO " +this.force2str(SET("MARK")) this.aSetStatus[55] = "SET MEMOWIDTH TO " +this.force2str(SET("MEMOWIDTH")) this.aSetStatus[56] = "SET MENU " +this.force2str(SET("MENU")) this.aSetStatus[57] = "SET MESSAGE TO " +iif(!empty(this.force2str(SET("MESSAGE",1))),"'"+this.force2str(SET("MESSAGE",1))+"'","") this.aSetStatus[58] = "SET MOUSE " +this.force2str(SET("MOUSE")) this.aSetStatus[59] = "SET MULTILOCKS " +this.force2str(SET("MULTILOCKS")) this.aSetStatus[60] = "SET NEAR " +this.force2str(SET("NEAR")) this.aSetStatus[61] = "SET NOTIFY " +this.force2str(SET("NOTIFY")) this.aSetStatus[62] = "SET NULL " +this.force2str(SET("NULL")) this.aSetStatus[63] = "SET NULLDISPLAY TO " +'"'+this.force2str(SET("NULLDISPLAY"))+'"' this.aSetStatus[64] = "SET ODOMETER TO " +this.force2str(SET("ODOMETER")) this.aSetStatus[65] = "SET OLEOBJECT " +this.force2str(SET("OLEOBJECT")) this.aSetStatus[66] = "SET OPTIMIZE " +this.force2str(SET("OPTIMIZE")) this.aSetStatus[67] = "SET PALETTE " +this.force2str(SET("PALETTE")) this.aSetStatus[68] = "SET PATH TO " +this.force2str(SET("PATH")) this.aSetStatus[69] = "SET POINT TO " +this.force2str(SET("POINT")) this.aSetStatus[70] = "SET PRINTER " +this.force2str(SET("PRINTER")) this.aSetStatus[71] = "SET PRINTER TO " +this.force2str(SET("PRINTER",1)) this.aSetStatus[72] = "SET PROCEDURE TO " +this.force2str(SET("PROCEDURE")) this.aSetStatus[73] = "SET READBORDER " +this.force2str(SET("READBORDER")) this.aSetStatus[74] = "SET REFRESH TO " +this.force2str(SET("REFRESH")) this.aSetStatus[75] = "SET REPROCESS TO " +this.force2str(SET("REPROCESS")) this.aSetStatus[76] = "SET RESOURCE " +this.force2str(SET("RESOURCE")) this.aSetStatus[77] = "SET RESOURCE TO " +iif(file(this.force2str(SET("RESOURCE",1))),; '"'+this.force2str(SET("RESOURCE",1))+'"',"") this.aSetStatus[78] = "SET SAFETY " +this.force2str(SET("SAFETY")) this.aSetStatus[79] = "SET SCOREBOARD " +this.force2str(SET("SCOREBOARD")) this.aSetStatus[80] = "SET SECONDS " +this.force2str(SET("SECONDS")) this.aSetStatus[81] = "SET SEPARATOR TO " +this.force2str(SET("SEPARATOR")) this.aSetStatus[82] = "SET SHADOWS " +this.force2str(SET("SHADOWS")) this.aSetStatus[83] = "SET SPACE " +this.force2str(SET("SPACE")) this.aSetStatus[84] = "SET STATUS " +this.force2str(SET("STATUS")) this.aSetStatus[85] = "SET STATUS BAR " +this.force2str(SET("STATUS BAR")) this.aSetStatus[86] = "SET STICKY " +this.force2str(SET("STICKY")) this.aSetStatus[87] = "SET STRICTDATE TO " +this.force2str(SET("STRICTDATE")) this.aSetStatus[88] = "SET SYSFORMATS " +this.force2str(SET("SYSFORMATS")) this.aSetStatus[89] = "SET SYSMENU " +this.force2str(SET("SYSMENU")) this.aSetStatus[90] = "SET TALK "+this.force2str(SET("TALK")) this.aSetStatus[91] = "SET TYPEAHEAD TO " +this.force2str(SET("TYPEAHEAD")) this.aSetStatus[92] = "SET UDFPARMS " +this.force2str(SET("UDFPARMS")) this.aSetStatus[93] = "SET UNIQUE " +this.force2str(SET("UNIQUE")) this.aSetStatus[94] = "ON ERROR "+this.force2str(ON("ERROR")) this.aSetStatus[95] = "ON ESCAPE "+this.force2str(ON("ESCAPE")) this.aSetStatus[96] = "ON READERROR "+this.force2str(ON("READERROR")) this.aSetStatus[97] = "SET READBORDER "+this.force2str(SET("READBORDER")) this.aSetStatus[98] = "ON SHUTDOWN "+this.force2str(ON("SHUTDOWN")) this.aSetStatus[99] = "_SCREEN.FORECOLOR = "+this.force2str(_screen.forecolor) this.aSetStatus[100] = "_SCREEN.BACKCOLOR = "+this.force2str(_screen.backcolor) this.aSetStatus[101] = "_SCREEN.FONTNAME = "+'"'+this.force2str(_screen.fontname)+'"' this.aSetStatus[102] = "_SCREEN.FONTSIZE = "+this.force2str(_screen.fontsize) this.aSetStatus[103] = "_SCREEN.FONTBOLD = "+IIF(_screen.fontbold = .T.,".T.",".F.") this.aSetStatus[104] = "_SCREEN.FONTITALIC = "+IIF(_screen.fontitalic = .T.,".T.",".F.") this.aSetStatus[105] = "_SCREEN.FONTUNDERLINE = "+IIF(_screen.fontunderline = .T.,".T.",".F.") this.aSetStatus[106] = "_SCREEN.CAPTION = "+'"'+this.force2str(_screen.caption)+'"' EndProc PROTECTED procedure force2str && CONVERTS PARAMETER OF ANY DATATYPE TO CHARACTER PARAMETERS unknownMemVar local ms_x, m.lcF2SReturnValue DO CASE CASE ISNULL(m.unknownMemVar) m.lcF2SReturnValue = "" CASE TYPE("m.unknownMemVar") = "C" m.lcF2SReturnValue = m.unknownMemVar CASE TYPE("m.unknownMemVar") = "T" m.lcF2SReturnValue = EVALUATE("TTOC(m.unknownMemVar)") CASE TYPE("m.unknownMemVar") = "N" m.lcF2SReturnValue = ALLTRIM(STR(m.unknownMemVar,25,10)) FOR ms_x = 1 TO 11 IF SUBSTR(m.lcF2SReturnValue,LEN(m.lcF2SReturnValue),1) = "0" ; OR SUBSTR(m.lcF2SReturnValue,LEN(m.lcF2SReturnValue),1) = "." m.lcF2SReturnValue = SUBSTR(m.lcF2SReturnValue,1,LEN(m.lcF2SReturnValue)-1) ELSE EXIT ENDIF NEXT CASE TYPE("m.unknownMemVar") = "D" and mkst_pcount = 1 m.lcF2SReturnValue = DTOC(m.unknownMemVar) CASE TYPE("m.unknownMemVar") = "L" and mkst_pcount = 1 IF m.unknownMemVar = .T. m.lcF2SReturnValue = ".T." ELSE m.lcF2SReturnValue = ".F." ENDIF ENDCASE RETURN m.lcF2SReturnValue endproc Procedure Destroy() *!* reset work area settings *!* if version(2) <> 0 *!* wait window "Restoring environment settings. Please wait..." nowait *!* endif if this.lReturnWorkAreaSettings = .t. and ; used(this.cCurrentAlias) and ; this.cCurrentAlias = alias(this.nCurrentWorkArea) *!* work area is still open, reselect it select (this.cCurrentAlias) if this.lReturn2IndexOrder = .t. and ; !empty(this.nCurrentIndexNum) and ; this.cCurrentIndexOrder = tag(this.nCurrentIndexNum) *!* index still exists set order to it set order to (this.cCurrentIndexOrder) endif if this.lReturn2Recno = .t. and !empty(this.nCurrentRecno) and ; this.nCurrentRecno <= reccount() *!* record number is not out of range - move record pointer back to same record go (this.nCurrentRecno) endif endif *!* reset settings local m.lcRestoreSetting, m.lnRsCnt for m.lnRsCnt = 1 to alen(this.aSetStatus) m.lcRestoreSetting = this.aSetStatus[m.lnRsCnt] *!* if version(2) <> 0 *!* wait window m.lcRestoreSetting nowait *!* endif do case case m.lcRestoreSetting = "SET STATUS BAR ON" and set("status bar") = "ON" *!* avoid flashing status bar case "SET RESOURCE TO" $m.lcRestoreSetting and set("resource") = "OFF" *!* avoid setting resource to any file if off otherwise &lcRestoreSetting endcase next EndProc EndDefine