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:1window.tabcontrol -
The Tab control is the parent of the tab pages contained in
it:1window.tabcontrol.tabpageuo -
The tab page is the parent of the control contained in
it:1window.tabcontrol.tabpageuo.controlonpage
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 2 |
w_display.tab_1.tabpage_1.PowerTipText = & "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 2 3 |
// Get a reference to the Tab control // "This" refers to the tab page user object 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 2 3 4 5 6 7 8 9 10 11 |
tab tab_mytab userobject tabpage_generic tabpage_generic = This.GetParent() tab_mytab = tabpage_generic.GetParent() tabpage_generic.PowerTipText = & "Important property page" tab_mytab.PowerTips = TRUE 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 2 3 |
tab tab_settings tab_settings = This.GetParent() 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 2 3 4 |
uo_emprpt_page tabpage_current tabpage_current = This.Control[index] tabpage_current.dw_emp.Retrieve & (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.