| Home | Previous Lesson: Creating a Standard User Object Next Lesson: Creating a DataWindow User Object |
Events available to the standard CommandButton control are available to this user object. In order to customize our user object, PowerBuilder offers us the chance to declare variables, structures, functions and our own user events.
To complete our CommandButton user object, we need to add the functionality that displays MircroHelp when the mouse moves over the CommandButton. Let's declare an user defined event, ue_mousemove. Display the popup menu in the Script painter and select 'Go To > Events' menu option and select '(New Event)' from the DDLB, Alternately, you can select 'Event List' tab page and display popup menu and select Add menu option. Declare ue_mousemove event and map it to pbm_mousemove event id. Type the following script for the ue_mousemove event:
// Object: uo_CommandButton user object
// Event: ue_mousemove
w_mdi_frame.SetMicroHelp( This.Tag )
While creating a user object, try to avoid hard coding anything into the script. By hard coding in the script, you are reducing the flexibility of the user object, the cornerstone of their usefulness. In this case, we've used the THIS keyword, so that the displayed message depends on the underlying object.
Save the user object as uo_commandbutton and create a new window. Now, you may want to test this user object. Open the w_about window. Select 'Insert > Control > User object' from the menu. Select uo_CommandButton. Click on the window workspace next to the Done CommandButton. We have script for the Done CommandButton's clicked event. Copy that script to the new CommandButton's clicked event, and delete the Done CommandButton. Change the new CommandButton's name to cb_done and the text to "&Done". Similarly, replace all other CommandButtons. Define the help for each CommandButton in its TAG property; this can be done from the Properties sheet for each CommandButton.
Confused about what's happening? What's happening is that, we replaced all the standard PowerBuilder CommandButtons in w_about window with the user object of type CommandButton. That means, we are using our own CommandButton instead of PowerBuilder's standard CommandButton.
Now, save the window and run the application. Select Help > About menu option. Move the mouse over these CommandButtons and see if PowerBuilder displays help on the Statusbar.
The code written for the user object class is available to each user object instance placed in the window and changes to the user object class will be reflected in each instance of the object. This provides you with a code that is reusable, easier to maintain and takes less time to develop.
Let's now create a more complex standard user object that we can be used in our Product Management application.
| Home | Previous Lesson: Creating a Standard User Object Next Lesson: Creating a DataWindow User Object |