PowerBuilder – User Customization Service
Here is an easy to implement user customization service you can add to your Powerbuilder applications which stores configuration information in a database. This gives the added benefit of portability to the users as nothing is stored in files or the registry. It is PFC based but, with minor modifications, could be un-coupled from that if desired.
The main object is the n_cst_dbinifile NVO. The export of it can be downloaded from here. n_cst_dbinifile
Note the export makes use of the PFC n_cst_inifile NVO but this can be stripped out if desired.
The service allows for default values to be set up and used if the user does not have their own set up (or when you give them the option to undo all their changes). The service also keeps itself updated by retrieving the datastore at an interval of your choosing.
Database table (SQL Server)
You will need the following table added to your database:
create table cmnIniFile ( fileName varchar(255) NULL, userCode varchar(255) NULL, sectionName varchar(32) NULL, keyName varchar(255) NULL, valusString varchar(8000) NULL )
The dataobject is called d_dbinifile and has two retrieval args:
as_filename (string)
as_userCode (string)
The SQL for the dataobject is:
SELECT cmnIniFile.filename, cmnIniFile.userCode, cmnIniFile.sectionName, cmnIniFile.keyName, cmnIniFile.valueString FROM cmnIniFile WHERE ( cmnIniFile.filename = :as_filename ) AND ( ( cmnIniFile.userCode = :as_userCode ) OR ( cmnIniFile.userCode = 'DEFAULT' ) ) ORDER BY cmnIniFile.filename ASC, cmnIniFile.userCode ASC, cmnIniFile.sectionName ASC, cmnIniFile.keyName ASC
Implementation
In the application manager object (n_cst_appmanager) for the application you need:
n_cst_dbIniFile inv_userIniFile // instance variable
and a method (of_create_ini) which is called as part of application start up.
long ll_rc string ls_appName ls_appName = of_getAppName () //set in constructor by of_setappname method inv_userIniFile = create n_cst_dbIniFile ll_rc = inv_userIniFile.of_register (SQLCA, ls_appName, gs_username) //gs_username set at log in if ll_rc < 0 then messagebox ("Application Open Error", "Unable to register the user's DB INI file.") end if return ll_rc
In the destructor event of the app manager object you should destroy the inv_userIniFile object.
In various windows with user specified settings which you wish to implement:
string ls_flag ls_flag = gnv_app.inv_userIniFile.of_getString('Defaults','Maximized','N')// arguments: section, value, default // do some processing based on the ls_flag value // get another setting ls_flag = gnv_app.inv_userIniFile.of_getString('Defaults','Grid Order','N') // do some other processing based on the ls_flag value
Now we want to save settings (window size and position in this example)
gnv_app.inv_userIniFile.of_setString(this.title, 'xpos', string(this.X)) gnv_app.inv_userIniFile.of_setString(this.title, 'ypos', string(this.Y)) gnv_app.inv_userIniFile.of_setString(this.title, 'height', string(this.height)) gnv_app.inv_userIniFile.of_setString(this.title, 'width', string(this.width))
In general this would be done as part of the window close event.