The reference pronouns in PB

Source: Internet
Author: User
Tags variables

Author: Xingda Computer technology company (www.study01job.com) Guo Baoli

PowerBuilder provides 4 pronouns, which are this,parent,parentwindow,super, which can be used in place of object names to refer to objects, thereby enhancing the portability of programs. For example, suppose that there is a statement close (W_main) on the clicked event with the key "exit" in the window W_main, which closes the window W_main, and when the name of the window changes, the statement must be modified to perform correctly; using a pronoun is different, close (parent) It can still be executed correctly when the window name changes, and the control can still be used correctly if it is copied to another window without modification.

A pronoun refers to a different object based on the circumstances surrounding the object in which the script resides. For example, the button on the window, its clicked event, the script's parent is to refer to the window of the key; within the visual user object, the key clicked event, the script's parent is the user object that refers to the key. Table 5-3 lists the objects that each of the pronouns can use and the objects they refer to.

Table 5-3 refers to pronouns

The use of positional meanings in pronouns

Control parent window in parent window

Control user objects in a visual user object

Menu Top Level Menu

This window, custom user objects, application objects, control objects, or controls themselves

The window where the ParentWindow menu runs

Super child object or control parent object or control

child window or User object direct ancestor

A direct ancestor of a control user object in a child window or user object

These pronouns are described in detail below.

1. This

A pronoun is used to refer to the current object. This refers to the object in which the script resides, although it is the same as the name used to directly use the object, but this is more versatile when the object is renamed or when the script is copied to an event in another object, using this pronoun to refer to the object in which it is scripted, so that Developers do not have to write code by pointing a script to a particular object name. For example, when you write a script in a key, you can use this to write a script for this class of keystrokes, not just for the current key. This helps developers develop more generic scripts.

In the script of an object or control, a developer can refer to an object or control's properties without referring to the pronoun this or its own object name, but a good programming style should promote the use of the pronoun this to make the script clearer and easier to read. For example, the following is a statement under the key clicked event, omitting the pronoun this is still able to complete the THIS.X=THIS.X+50 task:

X=x+50

However, if a variable x is defined in the script above, execution of the script does not accomplish the intended function. PowerBuilder when a variable is processed, it is assumed that x is the variable, not the x-coordinate of the key. When there are global variables and instance variables with the same name, PowerBuilder will first find the global variable, and need to refer to the local variable, you must use the pronoun, because the instance variable belongs to the window or user object, the pronoun should refer to the window or the user object. So, programming in a window or a user object uses the pronoun this, which is programmed on a control in the window or on the controls in a user object, meaning that the pronoun is parent. For example, there is an instance variable with the same name as the global variable test_str in a window in which the statement referencing the instance variable is THIS.TEST_STR, and the statement referencing the instance variable on the control of that window is parent.test_str, of course, the global variable can be used directly.

You can also use this in the parameters of a function to pass the object that calls the function. For example:

Wf_setposition (This)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.