Creating tab pages only when
needed
The user might never look at all the tab pages in your Tab
control. You can avoid the overhead of creating graphical
representations of the controls on all the tab pages by checking Create
on Demand on the Tab control’s General property page or setting the
CreateOnDemand property to TRUE.
The controls on all the tab pages in a Tab control are always
instantiated when the Tab control is created. However, when Create on
Demand is checked, the Constructor event for controls on tab pages is
not triggered and graphical representations of the controls are not
created until the user views the tab page.
Constructor events on the selected tab page
Constructor events for controls on the selected tab page are
always triggered when the Tab control is created.
Tradeoffs for Create on
Demand
A window will open more quickly if the creation of graphical
representations is delayed for tab pages with many controls. However,
scripts cannot refer to a control on a tab page until the control’s
Constructor event has run and a graphical representation of the control
has been created. When Create on Demand is checked, scripts cannot
reference controls on tab pages that the user has not viewed.
Whether a tab page has been
created
You can check whether a tab page has been created with the
PageCreated function. Then, if it has not been created, you can trigger
the constructor event for the tab page using the CreatePage
function:
|
1 2 3 |
IF tab_1.tabpage_3.PageCreated() = FALSE THEN tab_1.tabpage_3.CreatePage() END IF |
You can check whether a control on a tab page has been created by
checking whether the control’s handle is nonzero. If so, the control has
been created.
|
1 |
IF Handle(tab_1.tabpage_3.dw_list) > 0 THEN ... |
Changing CreateOnDemand during
execution
If you change the CreateOnDemand property to FALSE in a script,
graphical representations of any tab pages that have not been created
are created immediately.
It does not do any good to change CreateOnDemand to TRUE during
execution, because graphical representations of all the tab pages have
already been created.
Creating tab pages
dynamically
If CreateOnDemand is FALSE, you can set the label for a
dynamically created tab page in its Constructor event, using the
argument to OpenTabWithParm that is passed to the Message object. If
CreateOnDemand is TRUE, you need to set the label when the tab page is
instantiated, because the Constructor event is not triggered until the
tab is selected. The following script in a user event that is posted
from a window’s open event opens five tab pages and sets the label for
each tab as it is instantiated:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
int li_ctr string is_title THIS.setredraw(false) FOR li_ctr = 1 to 5 is_title = "Tab#" + string(li_ctr) tab_test.opentabwithparm(iuo_tabpage[li_ctr], & is_title, 0) iuo_tabpage[li_ctr].text = is_title //set tab label NEXT THIS.setredraw(true) RETURN 1 |