Introduction to PowerBuilder

HomePrevious Lesson: Special Characters
Next Lesson: Errors and Warnings

PowerScript Pronouns

When working with controls and windows, there are three very important pronouns that you may find useful:

Pronoun

Description

This

Represents the object for which the code is written. For example, if you write Close(this) for a window event, it closes the window. Writing the same code for a window control would produce an error since you can't close a window control. If you write This.Visible = FALSE for any control, it hides that control when that code is executed.

Parent

Represents the object that contains the object you are working with. For example, the Parent for a window control is the window that contains the control.

ParentWindow

This is used exclusively in menu scripts and refers to the window to which a menu is attached.

Using these pronouns can save you the time and more over make the code reusable. For example, write a generic script that closes a window and use it for all your windows. Let's rewrite the above code to hide and show the cb_left CommandButton.

Conventional Code

New Code using PowerScript Pronouns

IF cb_left.visible THEN Cb_left.Hide() Cb_right.text = "&Show" ELSE Cb_left.Show() Cb_right.text = "&Hide" END IF

IF cb_left.visible THEN cb_left.Hide() THIS.text = "&Show" ELSE cb_left.Show() THIS.text = "&Hide" END IF

Until now, we didn't write code to close the window. Place a new CommandButton in the window and write the following code for its Clicked event:
Close(Parent)

When the user clicks this CommandButton, PowerBuilder will close the window. That is because the CommandButton is placed in a window and referring to PARENT from its script means that we are referring to the window. Close(This) can't be used, because, you can't close a CommandButton; you can only hide it.
HomePrevious Lesson: Special Characters
Next Lesson: Errors and Warnings