Referring to tab pages in scripts
Dot
notation allows you to refer to individual tab pages and controls
on those tab pages:
-
The window or user
object containing the Tab control is its parent:1<span>window</span>.<span>tabcontrol</span> -
The Tab control is the parent of the tab pages contained
in it:1<span>window</span>.<span>tabcontrol</span>.<span>tabpageuo</span> -
The tab page is the parent of the control contained
in it:1<span>window</span>.<span>tabcontrol</span>.<span>tabpageuo</span>.<span>controlonpage</span>
For example, this statement refers to the PowerTips property
of the Tab control tab_1 within the
window w_display:
|
1 |
w_display.tab_1.PowerTips = TRUE |
This example sets the PowerTipText property of tab page tabpage_1:
|
1 |
w_display.tab_1.tabpage_1.PowerTipText = &<br>   "Font settings" |
This example enables the CommandButton cb_OK on
the tab page tabpage_doit:
|
1 |
w_display.tab_1.tabpage_doit.cb_OK.Enabled = TRUE |
Generic coding
You can use the Parent pronoun and GetParent function
to make a script more general.
Parent pronoun
In a script for any tab page, you can use the Parent pronoun to
refer to the Tab control:
|
1 |
Parent.SelectTab(This) |
GetParent function
If you are in an event script for
a tab page, you can call the GetParent function
to get a reference to the tab page’s parent, which is the Tab
control, and assign the reference to a variable of type Tab.
In an event script for a user object that is used as a tab
page, you can use code like the following to save a reference to
the parent Tab control in an instance variable.
This is the declaration of the instance variable. It can hold
a reference to any Tab control:
|
1 |
tab itab_settings |
This code saves a reference to the tab page’s parent
in the instance variable:
|
1 |
// Get a reference to the Tab control<br>// "This" refers to the tab page user object<br>itab_settings = This.GetParent() |
In event scripts for controls on the tab page, you can use GetParent twice
to refer to the tab page user object and its Tab control:
|
1 |
tab tab_mytab<br>userobject tabpage_generic<br> <br>tabpage_generic = This.GetParent()<br>tab_mytab = tabpage_generic.GetParent()<br> <br>tabpage_generic.PowerTipText = &<br>   "Important property page"<br>tab_mytab.PowerTips = TRUE<br> <br>tab_mytab.SelectTab(tabpage_generic) |
Generic variables for controls have limitations
The type of these variables is the basic PowerBuilder object
type—a variable of type Tab has no knowledge of the tab
pages in a specific Tab control and a variable of type UserObject
has no knowledge of the controls on the tab page.
In this script for a tab page event, a local variable is assigned
a reference to the parent Tab control. You cannot refer to specific
pages in the Tab control because tab_settings does
not know about them. You can call Tab control functions and refer
to Tab control properties:
|
1 |
tab tab_settings<br>tab_settings = This.GetParent()<br>tab_settings.SelectTab(This) |
User object variables
If the tab page is an independent user object, you can define
a variable whose type is that specific user object. You can now
refer to controls defined on the user object, which is the ancestor
of the tab page in the control.
In this script for a Tab control’s event, the index
argument refers to a tab page and is used to get a reference to
a user object from the Control property array. The example assumes
that all the tab pages are derived from the same user object uo_emprpt_page:
|
1 |
uo_emprpt_page tabpage_current<br>tabpage_current = This.Control[index]<br>tabpage_current.dw_emp.Retrieve &<br>   (tabpage_current.st_name.Text) |
The Tab control’s Control property
The Control property array contains references to all the
tab pages in the control, including both embedded and independent
user objects. New tab pages are added to the array when you insert
them in the painter and when you open them in a script.