Hackers Guide to Visual FoxPro 7.0
Set, Set(), SYS(2001)
Probably the single most destructive command in the language, the SET command gives Visual FoxPro much of its power and much of its flakiness.| Usage | SET SettingName ON | OFF SET SettingName TO uExpression |
| ANSI AUTOSAVE BLOCKSIZE CARRY CENTURY COLLATE CONFIRM CURRENCY | DATABASE DATE DECIMALS DELETED DELIMITERS EXACT EXCLUSIVE FIELDS FIXED | HOURS LOCK MARK TO MEMOWIDTH MULTILOCKS NEAR NULL POINT | REFRESH REPROCESS SAFETY SET SECONDS SEPARATOR SYSFORMATS TALK UNIQUE |
SET commands range from SET ALTERNATE to SET XCMDFILE. We won't cover all of them here, but we'll point out some generalities. To every rule there is an exception, and SET commands prove this time and time again.
In general, there are two ways you'd want to use a SET command: globally, so that it takes effect, and you can assume that condition, throughout your application; and locally, in order to take advantage of a feature only available within one SET mode. Let's talk about each of these needs and strategies for achieving them. Global settings are settings you would probably like to establish once and be done with it. FoxPro offers three ways for you to accomplish this. First, many settings are available through the Tools-Options dialog and are stored in the Windows Registry (for more details, see "Registration Database"). Second, all settings stored within the CONFIG.FPW file are read on setup and are in effect for the entire session, unless reset, or unless you've accidentally specified the wrong configuration file (check "Configuration Files" for more details on this). Finally, you can set up a program to explicitly issue the appropriate SET commands. Depending on your specific needs, each of these methods may be best for you. Using the Registry is great. It's consistent with other Windows applications. The Registry functions and structure allow you to set up more than one user on the same hardware, each with her own settings. The latest versions of Windows 95 and NT provide the ability for administrators to manage Registry entries across the network. However, Registry settings are not read at startup by runtime modules, so you'll need to resort to alternative methods for runtime environments. However, don't give up on the Registry altogether. Even if you decide to programmatically load your settings, you might want to consider keeping these settings in the Registry. In many cases, it can be simpler to embed a CONFIG.FPW file into your .EXE, especially for settings you will not allow users to change. Add the CONFIG.FPW (this must be its name) to the Project Manager as a file, and the settings are read on startup. If you do want or need the users to change settings in the CONFIG.FPW, you can include the file by any name on the disk and point to it with the -C startup switch—see "CONFIG.FPW" for details. Finally, the programmatic method offers a lot of flexibility. Store all your settings in a table, perhaps stored centrally for ease of maintenance and to allow your users to move from machine to machine, and read each of the settings and process them. You might consider this method with the Registry as your centralized database—if you're using Windows 95 and/or Microsoft's System Management Server. Local settings, on the other hand, are those you need in effect for one small set of commands to ensure they work correctly. The safest, though not necessarily bulletproof, method of manipulating SET commands within a "black box" function is to preserve the initial value, change the setting to the desired one, perform the SET-dependent function, and then immediately restore the setting, as in the following code snippet:cDateSet = SET("DATE") SET DATE ANSI sMyDate = CTOD(cYear+"."+cMonth+"."+cDay) SET DATE &cDateSet The local setting method above does have its hazards. If any function or command can interrupt the execution of this snippet, you're back into the infinite-state machine—who knows what will happen? Two situations where we know this may happen are the execution of ON KEY LABEL functions and the automatic refreshing of a Grid/Browse. As usual, a little defensive programming can minimize the hazards. Within code called by ON KEY LABEL, use the same technique as above to save-change-restore any settings you need to work. Grids/Browses are a little trickier—the danger occurs if you change a setting that the grid depends upon for a display function, such as the SET DATE function above. The only work-around we know of is to use naming conventions in such a way that you'll know when it is unwise to make such changes. An alternative is not to use specific SET commands, such as SET DATE, within your routines if you plan to use grids—instead, use CASE statements to determine the current environment and use those settings to properly process your routine. Take a look at the examples included with the BITx() functions for some ideas on how to do this.
| Usage | uRetVal = SET( cSetting [, 1 | 2 | 3 ] ) uRetVal = SYS( 2001, cSetting [, 1 | 2 | 3 ] ) |
| Example | cDelSet = SET("DELETED") |
| See Also | Display Status, Configuration Files, Registration Database |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории