Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cool idea for SET commands
Message
De
27/07/2004 10:04:05
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
À
27/07/2004 09:23:21
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00928029
Message ID:
00928284
Vues:
40
>Actually, that is not entirely accurate. By using push/pop classes you can code with more freedom. There are those that will say, you shouldn't have more than one exit point. You should have the freedom to code without petty rules. You should not have to worry about simple human mistakes, like forgetting to reset. There are fewer lines of code to write, so you should be able to code faster. In my example I'm showing that the push/pop class could also change the SET command. IMO, you are most likely pushing the value because you want to change it. I put the vartype check before the set safety. With the pushpop, I could accidentally put the vartype check after the pushpop createobject and it would still work. There could be a business requirement requiring an early exit.

>
LPARAMETERS m.tcVar
>IF VARTYPE(m.tcVar) # "C"
>  RETURN .F.
>ENDIF
>LOCAL m.lcSafety
>m.lcSafety = SET("SAFETY")
>SET SAFETY OFF
>* ... some processing
>IF somebusinesscondition = .F.
>  SET SAFETY &lcSafety. && You have to remember to reset it here.
>  RETURN .F.
>ENDIF
>DO SOMETHING
>SET SAFETY &lcSafety.
>RETURN
While I agree that the cSet class (which exists as a freebie in the CodeBook, and is inherited in at least one CodeBook-derived framework that I used) makes things simple, your example of an early exit is slightly wrong - the exit is not early enough. If you're exiting early, you should do so before you change any SETtings:
LPARAMETERS m.tcVar
IF VARTYPE(m.tcVar) # "C"
  RETURN .F.
ENDIF
IF not somebusinesscondition
  RETURN .F.
ENDIF
* now we're doing business, save settings and do it
LOCAL m.lcSafety
m.lcSafety = SET("SAFETY")
SET SAFETY OFF
* ... some processing
DO SOMETHING
* ...done, restore.
SET SAFETY &lcSafety.
RETURN
Of course, there may be other exits that may be required during the business part, but these may be bracketed using a simple status variable:
lOK=SomeCheck()
if lOK
   * do some more
   lOK={new check condition}
endif

if lOK
   * keep on processing
   lOK={another check condition}
endif
* done, restore
This way you don't have to have other exits but the early exits (before you disturb the settings) and one final exit (where you restore the settings).

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform