INI / Registry Router |
Ver. 1.00 Contributed by Lee Hendricks |
What
n_cst_appmanager
Why
PowerBuilder applications are often deployed to multiple platforms:
Windows 95/NT/3.1, Macintosh, UNIX. Windows95 and Windows NT applications can use the registry to store application and user settings, whereas other platforms must rely on INI files.
Determining where to obtain these settings can result in redundant code. (For example, look in pfc_w_master's open event. There is quite a bit of code for the preference service to restore the user's last settings. Similar redundant code is found in the close event to save the settings.)
Furthermore dynamically changing the source of the application and user settings requires overriding the of_isRegistryAvailable() function to change it's original meaning.
How
4 polymorphic functions are included to determine where to obtain application and user settings:
public function string of_getappvalue (string as_section, string as_label, string as_default) public function boolean of_setappvalue (string as_section, string as_label, string as_value) public function string of_getuservalue (string as_section, string as_label, string as_default) public function boolean of_setuservalue (string as_section, string as_label, string as_value) |
These functions merely check the is_source instance variable, which determines the appropriate source for the requested setting. For example, here's the code for of_getAppValue():
/* Return value of a specified label from either Windows registry or the application's INI file. */ string ls_registryValue IF is_source= "registry" THEN IF NOT of_getAppRegistryValue(as_section, as_label, ls_registryValue) THEN RETURN as_default ELSE RETURN ls_registryValue END IF ELSE RETURN of_getAppProfileString(as_section, as_label, as_default) END IF |
The is_source instance variable is set in the constructor event based on whether the registry is available on the specific platform:
/* Determine the initial source value. */ IF this.of_isRegistryAvailable() THEN is_source = "registry" END IF |
An example call would look like this:
// Get the location of the user's log file.
ls_logFile = gnv_app.of_getUserValue("General", "LogFileLocation", "log.txt")
|
Notes:
1) These functions rely on the PFC app/user key/ini settings. Make sure you call these functions in your application manager. Example:
// constructor event
of_SetAppKey("hkey_local_machine\software\My Company\My Application")
of_SetAppIniFile("MyApp.ini")
of_SetUserIniFile("MyApUser.ini")
// pfc_logon event - after successful logon
of_SetUserKey(of_getAppKey() + "\" + of_getUserId())
|
2) If the platform is Windows95 or Windows NT, but you want to use an INI file, you may call of_setSource("ini") to override the default source setting.
| Download the source code for the INI / Registry Router. | About the extension contributor |
Interested in contributing material to this web site? Send an email to submit@pfcguide.com, but don't forget to check the contribution guidelines first.
For information or suggestions about this web site please contact webmaster@pfcguide.com
PFCGuide is
sponsored by Dynamic Technology Group.
The information on this site is provided for advice only and not to be considered a
contract or a liability against Dynamic
Technology Group.