Self-initializing persistent Configuration class instance
Cfg([<oConfig>]) --> oCfg
<oConfig> If a Configuration instance is passed as an argument, that instance becomes the active configuration for subsequent calls to Cfg().
An initialized Configuration instance. If available, this instance will be read from the persistent storage diskfile MY_HOMEPATH+"USER.CFG".
The Cfg() function can be treated as a globally available and persistent Configuration instance. Rather than worry about instantiating the class and making sure an assigned variable is in the proper scope, access to a module's configuration is performed through the Cfg() function, called with no arguments.
One virtue of the Cfg() function is that it will initialize its STATIC configuration variable whenever a first runtime call is made to the function. There is no need to place an special initializing call to Cfg() at the beginning of module code. If a particular runtime sequence never calls the Cfg() function, that ipso facto means there was no need to access configuration data or methods.
For flexibility, it is possible to pass as argument a specific Configuration instance which is to act as the subsequent configuration. However, it is not currently anticipated that there will be any need to use this parameter option, since the Configuration instance accessed via Cfg() can have its data changed either persistently or non-persistently by using the associated class' methods and setting its instance data.
? Cfg():className() // Result: "Configuration"
// Check a configuration value
DrawGraBox(22, 0, 23, 79, "FLAT_PALE_BIGTEXT", cTitle)
// Set, serialize, and save a configuration value
Cfg():GrayBar := .T.
// Make additional config change, but do not save to diskfile
Cfg():ColorScheme:DialogBG := GRA_CLR_YELLOW
Source file is Configuration.prg