The pronoun This in a PocketBuilder script refers to the window, user object, menu, application object, or control that owns the current script.
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, PocketBuilder 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.
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