Using inheritance to build user objects
When you build a user object that inherits its definition
(properties, events, functions, structures, variables, controls,
and scripts) from an existing user object, you save coding time.
All you have to do is modify the inherited definition to meet the
requirements of the current application.
For example, suppose your application has a user object u_file_view that
has three CommandButtons:
- List–displays
a list of files in a list - Open–opens the selected file and displays
the file in a MultiLineEdit control - Close–displays a message box and then closes
the window
If you want to build another user object that is exactly like
the existing u_file_view except
that it has a fourth CommandButton, you can use inheritance to build
the new user object, and then all you have to do is add the fourth CommandButton.
To use inheritance to build a descendent user
object:
-
Click the Inherit button in the PowerBar,
or select File>Inherit from the menu bar. -
In the Inherit From Object dialog box, select
User Objects from the Objects of Type drop-down list. -
Select the target as well as the library or libraries
you want to look in.
Displaying user objects from many libraries To find a user object more easily, you can select more than
one library in the Libraries list. Use Ctrl+Click to toggle
selected libraries and Shift+Click to select a range. -
Select the user object you want to use to create
the descendant, and click OK.The
selected object displays in the User Object painter and the title
bar indicates that the object is a descendant. -
Make any changes you want to the user object.
-
Save the user object with a new name.
Using the inherited information
When you build and save a user object, PowerBuilder treats the
object as a unit that includes:
- The
object (and any controls within the object if it is a custom visual
user object) - The object’s properties, events, and scripts
- Any variables, functions, or structures declared
for the object
When you use inheritance to build a new user object, everything
in the ancestor user object is inherited in the direct descendant
and in its descendants in turn.
Ancestor’s instance variables display
If
you create a user object by inheriting it from a custom class or
standard class user object that has public or protected instance
variables with simple datatypes, the instance variables display
and can be modified in the descendent user object’s Properties
view.
All public instance variables with simple datatypes such as integer, boolean, character, date, string,
and so on display in the descendant. Instance variables with the any or blob datatype
or instance variables that are objects or arrays do not display.
What you can do in the descendant
You can do the following in a descendent user object:
- Change the values of the properties and the variables
- Build scripts for events that do not have scripts
in the ancestor - Extend or override the inherited scripts
- Add controls (in custom visual user objects)
- Reference the ancestor’s functions and
events - Reference the ancestor’s structures if
the ancestor contains a public or protected instance variable of
the structure data type - Access ancestor properties, such as instance variables,
if the scope of the property is public or protected - Declare variables, events, functions, and structures
for the descendant
What you cannot do in the descendant
In a descendent user object, you cannot delete controls inherited
from a custom visual user object. If you do not need a control in
a descendent user object, you can make it invisible.
Understanding inheritance
The issues concerning inheritance with user objects are the
same as the issues concerning inheritance with windows and menus.
See Chapter 12, “Understanding Inheritance ,” for
more information.