Pronouns

Description

PowerScript has pronouns that allow you to make a general reference to an object or control. When you use a pronoun, the reference remains correct even if the name of the object or control changes.

Usage

You can use pronouns in function and event scripts wherever you would use an object's name. For example, you can use a pronoun to:

  • Cause an event in an object or control

  • Manipulate or change an object or control

  • Obtain or change the setting of a property

The following table lists the PowerScript pronouns and summarizes their use.

This pronoun

In a script for a

Refers to the

This

Window, custom user object, menu, application object, or control

Object or control itself

Parent

Control in a window

Window containing the control

 

Control in a custom user object

Custom user object containing the control

 

Menu

Item in the menu on the level above the current menu

Super

descendant object or control

Parent

 

descendant window or user object

Immediate ancestor of the window or user object

 

Control in a descendant window or user object

Immediate ancestor of the control's parent window or user object


ParentWindow property

You can use the ParentWindow property of the Menu object like a pronoun in Menu scripts. It identifies the window that the menu is associated with when your program is running. For more information, see the the section called “Referring to objects in your application” in Users Guide.

The rest of this section describes the individual pronouns in detail.

Parent pronoun

Description

Parent in a PowerBuilder script refers to the object that contains the current object.

Usage

You can use the pronoun Parent in scripts for:

  • Controls in windows

  • Custom user objects

  • Menus

Where you use Parent determines what it references:

Window controls

When you use Parent in a script for a control (such as a CommandButton), Parent refers to the window that contains the control.

User object controls

When you use Parent in a script for a control in a custom user object, Parent refers to the user object.

Menus

When you use Parent in a menu script, Parent refers to the menu item on the level above the menu the script is for.

Examples

Window controls

If you include this statement in the script for the Clicked event in a CommandButton within a window, clicking the button closes the window containing the button:

Close(Parent)

If you include this statement in the script for the CommandButton, clicking the button displays a horizontal scroll bar within the window (sets the HScrollBar property of the window to true):

Parent.HScrollBar = TRUE

User object controls

If you include this statement in a script for the Clicked event for a CheckBox in a user object, clicking the check box hides the user object:

Parent.Hide( )

If you include this statement in the script for the CheckBox, clicking the check box disables the user object (sets the Enabled property of the user object to false):

Parent.Enabled = FALSE

Menus

If you include this statement in the script for the Clicked event in the menu item Select All under the menu item Select, clicking Select All disables the menu item Select:

Parent.Disable( )

If you include this statement in the script for the Clicked event in the menu item Select All, clicking Select All checks the menu item Select:

Parent.Checked = TRUE

This pronoun

Description

The pronoun This in a PowerBuilder script refers to the window, user object, menu, application object, or control that owns the current script.

Usage

Why include This

Using This allows you to make ownership explicit. The following statement refers to the current object's X property:

This.X = This.X + 50

When optional but helpful

In the script for an object or control, you can refer to the properties of the object or control without qualification, but it is good programming practice to include This to make the script clear and easy to read.

When required

There are some circumstances when you must use This. When a global or local variable has the same name as an instance variable, PowerBuilder finds the global or local variable first. Qualifying the variable with This allows you to refer to the instance variable instead of the global variable.

Examples

Example 1

This statement in a script for a menu places a check mark next to the menu selection:

This.Check( )

Example 2

In this function call, This passes a reference to the object containing the script:

ReCalc(This)

Example 3

If you omit This, "x" in the following statement refers to a local variable x if there is one defined (the script adds 50 to the variable x, not to the X property of the control). It refers to the object's X property if there is no local variable:

x = x + 50

Example 4

Use This to ensure that you refer to the property. For example, in the following statement in the script for the Clicked event for a CommandButton, clicking the button changes the horizontal position of the button (changes the button's X property):

This.x = This.x + 50

Super pronoun

Description

When you write a PowerBuilder script for a descendant object or control, you can call scripts written for any ancestor. You can directly name the ancestor in the call, or you can use the reserved word Super to refer to the immediate ancestor.

Usage

Whether to use Super

If you are calling an ancestor function, you only need to use Super if the descendant has a function with the same name and the same arguments as the ancestor function. Otherwise, you would simply call the function with no qualifiers.

Restrictions for Super

You cannot use Super to call scripts associated with controls in the ancestor window. You can only use Super in an event or function associated with a direct descendant of the ancestor whose function is being called. Otherwise, the compiler returns a syntax error.

To call scripts associated with controls, use the CALL statement.

See the discussion of CALL.

Examples

Example 1

This example calls the ancestor function wf_myfunc (presumably the descendant also has a function called wf_myfunc):

Super::wf_myfunc(myarg1, myarg2)

This example must be part of a script or function in the descendant window, not one of the window's controls. For example, if it is in the Clicked event of a button on the descendant window, you get a syntax error when the script is compiled.

Supplying arguments

Be certain to supply the correct number of arguments for the ancestor function.

Example 2

This example in a CommandButton script calls the Clicked script for the CommandButton in the immediate ancestor window or user object:

Super::EVENT Clicked()