Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Examining a class definition – PB Docs 100 – PowerBuilder Library

Examining a class definition – PB Docs 100

Examining a class definition

This section illustrates how to access a class definition
object and how to examine its properties to get information about
the class, its scripts, and its variables.

Getting a class definition object

To work with class information, you need a class definition
object. There are two ways to get a ClassDefinition object containing
class definition information.

For an instantiated object in your application

Use its ClassDefinition property.

For example, in a script for a button, this code gets the
class definition for the parent window:

For an object stored in a PBL

Call FindClassDefinition.

For example, in a script for a button, this code gets the
class definition for the window named w_genapp_frame from
a library on the application’s library list:

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:

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:

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:

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:

The list might look like this:

Parent

The ParentClass property of the ClassDefinition object reports
the parent (its container) specified in the object’s definition:

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:

Nested or child classes

The ClassDefinition object’s NestedClassList array
holds the classes the object contains.

note.gif 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 descendent window appears twice in the array for
the descendent 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.

This script searches the NestedClassList array in the ClassDefinition
object cd_windef to find a nested
DropDownListBox control:

note.gif 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.

Getting information about a class’s scripts

This section has code fragments illustrating how to get script
information from a ClassDefinition object called cd_windef.

For examples of assigning a value to cd_windef,
see “Getting a class definition
object”
.

List of scripts

The ScriptList array holds ScriptDefinition objects for all
the functions and events defined for a class. If a function is overloaded,
it will appear in the array more than once with different argument
lists. If a function or event has code at more than one level in
the hierarchy, it will appear in the array for each coded version.

This example loops through the ScriptList array and builds
a list of script names. All objects have a few standard functions,
such as ClassName and PostEvent, because all objects are inherited
from PowerObject:

This example amplifies on the previous one and accesses various
properties in the ScriptDefinition object. It reports whether the
script is a function or event, whether it is scripted locally, what
its return datatype and arguments are, and how the arguments are
passed:

Where the code is in the inheritance hierarchy You can check the IsLocallyScripted property to find out whether
a script has code at the class’s own level in the inheritance
hierarchy. By walking back up the inheritance hierarchy using the
Ancestor property, you can find out where the code is for a script.

This example looks at the scripts for the class associated
with the ClassDefinition cd_windef,
and if a script’s code is defined at this level, the script’s
name is added to a drop-down list. It also saves the script’s
position in the ScriptList array in the instance variable ii_localscript_idx.
The DropDownListBox is not sorted, so the positions in the list
and the array stay in sync:

Matching function signatures

When a class has overloaded functions, you can call FindMatchingFunction to find
out what function is called for a particular argument list.

For an example, see FindMatchingFunction in
the PowerScript Reference
.

Getting information about variables

This section has code fragments illustrating how to get information
about variables from a ClassDefinition object called cd_windef.
For examples of assigning a value to cd_windef,
see “Getting a class definition
object”
.

List of variables Variables associated with a class are listed in the VariableList
array of the ClassDefinition object. When you examine that array, you
find not only variables you have defined explicitly but also PowerBuilder object
properties and nested objects, which are instance variables.

This example loops through the VariableList array and builds
a list of variable names. PowerBuilder properties appear first, followed
by nested objects and your own instance and shared variables:

Details about variables

This example looks at the properties of each variable in the
VariableList array and reports its datatype, cardinality, and whether
it is global, shared, or instance. It also checks whether an instance
variable overrides an ancestor declaration:

This part presents a collection of techniques you can
use to implement user interface features in the applications you
develop with PowerBuilder. It includes building an MDI application,
using drag and drop in a window, and providing online Help for an
application.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x