Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SETting Environment
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00457247
Message ID:
00458050
Views:
21
>>>Why do I get a syntax error for this?
>>>
>>>**Setup.prg
>>>PUBLIC gcExclude
>>>gcExculde = SET("EXCLUSIVE")
>>>SET EXCLUSIVE OFF
>>>
>>>
>>>**Cleanup.prg
>>>SET EXCLUSIVE (gcExclude) <--- This is where I get a syntax error, why?
>>>

SET EXCLUSIVE takes a literal ON or OFF, not a string or name, so you can't use name resolution for the argument. You can either macroexpand the value, or do something like what Nadya does. I'd suggest creating a class that saves the state of the system environment and restores it on request or automagically when it gets destroyed; your code gets away from using PUBLICs, ismuch easier to implement, and allows several levels of state to be maintained separately. Your code would add the class below, and change to:
** Main Program
SET PROCEDURE TO StateClass
poInitialState = CREATEOBJ('SaveState')
poSetupState = Setup()
DO OtherStuff
**Setup.Prg
SET EXCLUSIVE OFF
* other stuff
RETURN CREATEOBJ('savestate', .t.)  && return a state object 
**Cleanup.Prg
poInitialState.Restore()
**StateClass.Prg
DEFINE CLASS SaveState AS LINE
   PROTECTED ExclusiveMode, SafetyMode, NearMode, MyAlias, ErrHand  && add whatever you want
   RestoreOnExit = .T.
PROCEDURE Init
   LPARAMETER tuNoAutoRestore  && Optional - allows state object which doesn't AutoRestore state on destruction
   WITH this
      =.RecordState()
      * allow object to not restore on destroy if optional .t. parameter given
      .RestoreOnExit = IIF(TYPE('tuNoAutoRestore') = 'L',! tuNoAutoRestore, .T.)
      * public property - it can be altered after init by assignment
   ENDWITH
ENDPROC
PROCEDURE RecordState
   WITH this
      .ExclusiveMode = SET('EXCLUSIVE')  && State of EXCLUSIVE
      .SafetyMode = SET('SAFETY')        && State of SAFETY
      .NearMode = SET('NEAR')            && State of NEAR
      .ErrHand = ON('Error')             && error handler in effect
      .MyAlias = ALIAS()                 && Alias selected on entry
   ENDWITH
ENDPROC
PROCEDURE Restore  && reset state when object first inited
                   && if more settings need to reset, define properties for them
                   && save detail 
   LOCAL cErrHand
   WITH this
      IF .ExclusiveMode = 'ON'
         SET EXCLUSIVE ON
      ELSE
         SET EXCLUSIVE OFF
      ENDIF
      IF .SafetyMode = 'ON'
         SET SAFETY ON
      ELSE
         SET SAFETY OFF
      ENDIF
      IF .NearMode = 'ON'
         SET NEAR ON
      ELSE
         SET NEAR OFF
      ENDIF
      IF EMPTY(.MyAlias) OR ! USED(.MyAlias)  && Empty work area or alias closed
         SELECT 0
      ELSE
         SELECT (.MyAlias)
      ENDIF
      cErrHand = .ErrHand  && can't macroexpand a property, so copy to a local
      ON ERROR &cErrHand   && for macroexpansion
   ENDWITH
ENDPROC
PROCEDURE DESTROY
   IF this.RestoreOnExit
      this.Restore()
   ENDIF
ENDPROC
ENDDEFINE

** If you want to experiment with the class, try:
SET PROC TO StateClass
SET SAFETY OFF
? 'init',set('safety')
oState = createobj('savestate')
SET SAFETY ON
oState = null
? 'after first',set('safety')
oState = createobj('savestate',.t.)
SET SAFETY ON
oState.Restore()
? 'restore explicit 2nd',set('safe')
SET SAFETY ON
oState=NULL
? 'last noauto',set('safe')
Essentially, whenever you have a state you'd like to preserve, you code:

oState = createobj('savestate')
*
* Do whatever you want to change the state
*
oState.Restore() && return to how we were when the object was created
*
* Change more settings
*
oState = NULL && the state is restored when the object is released

>>>
>>>p.s. these are just snippets from each of the respective programs.
>>>
>>>Thanks
>>>
>>>Elgin
>>
>>Elgin,
>>
>>Are you sure, you want use public variables for these settings? If they are defined in main program, you can use private variables instead. Better yet, make these settings to be properties of your application object. Then, in object destroy you can restore your settings back to original. BTW, I usually use this syntax:
>>
>>local lOldSetExact
>>lOldSetExact=set('exact')
>>set exact off
>>***** Other code *******
>>if lOldSetExact="ON"
>>   set exact on && Avoid macro, if possible
>>endif
>>
>
>Nadya,
>
>Thanks so much for the info. I will use your syntax. It works great. The reason I'm using a public variable is because I have 3 separate PRGs. One is Main.prg which calls Setup.prg then starts the event loop READ EVENTS. After the event loop I have a call to my Cleanup.prg. Not sure if there's any advantage to having 3 separate prgs instead of just one called MAIN.PRG. I read this in Booth's "Visual Foxpro Unleashed". What do you think? See any problems with having the 3, or should I be all in 1 for that program.
>
>Thanks again.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform