Data Access Worldwide Knowledge Base
Article ID 2269 Article Title EXAMPLE: User-configurable Toolbar Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2269 KBase Category VDF12 Date Created 11/29/2006 Last Edit Date 12/08/2006
Article Text
QUESTION:
On the toolbar we want to have six extra buttons that on a click calls a method to open a view, a dialog, a reportview and more. The problem is that those should call different objects depending on the user logged in. That information (say label for buttons, and object names) are stored in a user's table.
ANSWER:
The cToolBarButton class used for the individual buttons has a property called phmOnClick. This property can be set to the message identifier of a shared message at cToolBar object level. You can change this property dynamically when the user logs in.
Based on the above information I developed a subclass of cToolBarButton in which the button is (fully) configurable via an INI file. In the INI file there can be a definition for ALL users and a definition per user. The INI file could look like:
[oUserButton1.All]
Message=Msg_Activate_About
[oUserButton1.Vincent]
Message=Msg_Activate_About
Picture=Plus16.bmp
TransparentColor=$C0C0C0
Tooltip=This should be the tooltip
StatusHelp=This should display on the statusline
Destination=oClientArea
[oUserButton1.Pepe]
Message=Msg_Activate_About
Picture=Minus16.bmp
TransparentColor=$C0C0C0
Tooltip=This should be the tooltip
StatusHelp=This should display on the statusline
Destination=oClientArea
Label=This is the object label
The subclass first tries to find a defintion per user in the INI file. If this section - built from the short object name and the username - does not exist, the .ALL section is tried. When this all fails the button will be made disabled by setting the pbEnabled property to false.
The INI file information is read during the toolbar object construction but can be redone by sending the message DoReadUserButtonInfo to the button object(s). You could use the broadcast command to send the message to all button objects in the toolbar.
Enclosed is the class code for cUserDefinableToolbarButton, a toolbar object file named oUserDefinedToolbar.pkg and a UserButtons.ini file (place this in the DataPath) so that you can see how it is used.
NOTE: While the code expects the usage of Visual DataFlex 12, it is not specific for VDF12 only. If you want to use it in an older version (8.x is the oldest), you will need to make modifications (in the meta data) to get it compiled.
Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu
Web Links Related to this Article
File cUserDefineableToolbarButton.pkg
URL=http://www.dataaccess.com/KBasePublic/Files/2269.cUserDefineableToolbarButton.pkg
File oUserDefinedToolbar.pkg
URL=http://www.dataaccess.com/KBasePublic/Files/2269.oUserDefinedToolbar.pkg
File UserButtons.Ini
URL=http://www.dataaccess.com/KBasePublic/Files/2269.UserButtons.zip
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.