Getting detailed information about the class
This section has code fragments illustrating how to get
information from a ClassDefinition object called cd_windef.
For examples of assigning a value to cd_windef, see Getting a class definition
object.
Library
The LibraryName property reports the name of the library a class
has been loaded from:
|
1 |
s = cd_windef.LibraryName |
Ancestor
The Ancestor property reports the name of the class from which
this class is inherited. All objects are inherited from PowerBuilder
system objects, so the Ancestor property can hold a ClassDefinition
object for a PowerBuilder class. The Ancestor property contains a null
object reference when the ClassDefinition is for PowerObject, which is
the top of the inheritance hierarchy.
This example gets a ClassDefinition object for the ancestor of the
class represented by cd_windef:
|
1 2 |
ClassDefinition cd_ancestorwindef cd_ancestorwindef = cd_windef.Ancestor |
This example gets the ancestor name. Note that this code would
cause an error if cd_windef held the definition of PowerObject, because
the Ancestor property would be NULL:
|
1 |
ls_name = cd_windef.Ancestor.Name |
Use the IsValid function to test that the object is not
NULL.
This example walks back up the inheritance hierarchy for the
window w_genapp_frame and displays a list of its ancestors in a
MultiLineEdit:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
string s, lineend ClassDefinition cd lineend = "~r~n" cd = cd_windef s = "Ancestor tree:" + lineend DO WHILE IsValid(cd) s = s + cd.Name + lineend cd = cd.Ancestor LOOP mle_1.Text = s |
The list might look like this:
|
1 2 3 4 5 |
Ancestor tree: w_genapp_frame window graphicobject powerobject |
Parent
The ParentClass property of the ClassDefinition object reports the
parent (its container) specified in the object’s definition:
|
1 2 |
ClassDefinition cd_parentwindef cd_parentwindef = cd_windef.ParentClass |
If the class has no parent, ParentClass is a null object
reference. This example tests that ParentClass is a valid object before
checking its Name property:
|
1 2 3 |
IF IsValid(cd_windef.ParentClass) THEN ls_name = cd_windef.ParentClass.Name END IF |
Nested or child classes
The ClassDefinition object’s NestedClassList array holds the
classes the object contains.
NestedClassList array includes ancestors and
descendants
The NestedClassList array can include classes of ancestor
objects. For example, a CommandButton defined on an ancestor window
and modified in a descendant window appears twice in the array for the
descendant window, once for the window and once for its
ancestor.
This script produces a list of the controls and structures defined
for the window represented in cd_windef.
|
1 2 3 4 5 6 7 8 9 10 11 |
string s, lineend integer li lineend = "~r~n" s = s + "Nested classes:" + lineend FOR li = 1 to UpperBound(cd_windef.NestedClassList) s = s + cd_windef.NestedClassList[li].Name & + lineend NEXT mle_1.Text = s |
This script searches the NestedClassList array in the
ClassDefinition object cd_windef to find a nested DropDownListBox
control:
|
1 2 3 4 5 6 7 8 9 10 |
integer li ClassDefinition nested_cd FOR li = 1 to UpperBound(cd_windef.NestedClassList) IF cd_windef.NestedClassList[li].DataTypeOf & = "dropdownlistbox" THEN nested_cd = cd_windef.NestedClassList[li] EXIT END IF NEXT |
Class definitions for object instances as distinct from object
references
Getting a ClassDefinition object for an instantiated object,
such as an ancestor or nested object, does not give you a reference to
instances of the parent or child classes. Use standard PowerBuilder
programming techniques to get and store references to your
instantiated objects.