background image
C H A P T E R 3
Views
3-34
Using Views
Showing a Hidden View
3
In many cases, you might think that you need to create a view dynamically. However,
if the template can be defined at compile time, it's easier to do that and flag the
view as not visible. At the appropriate time, send it the
Open
message to show it.
The typical example of this is a slip, which you can usually define at compile time.
Using the Newton Toolkit (NTK), simply do not check the
vVisible
flag in the
viewFlags
slot of the view template. This will keep the view hidden when the
application is opened.
Also, it is important to declare this view in your application base view. For
information on declaring a view, see the section "View Instantiation" (page 3-26).
When you need to display the view, send it the
Open
message using the name
under which you have declared it (for example,
myView:Open()
).
This solution even works in cases where some template slots cannot be set until run
time. You can dynamically set slot values during view instantiation in any of the
following view methods:
ViewSetupFormScript
,
ViewSetupChildrenScript
, and
ViewSetupDoneScript
. You can also set
values in a declared view before sending it the
Open
message.
Adding to the stepChildren Array
3
If it is not possible to define the template for a view at compile time, the next best
solution is to create the template (either at compile time or run time) and add it to
the
stepChildren
array of the parent view using the
ViewSetupChildrenScript
method. This way, the view system takes care of
creating the view at the appropriate time (when the child views are shown).
For example, if you want to dynamically create a child view, you first define the
view template as a frame. Then, in the
ViewSetupChildrenScript
method of
its parent view, you add this frame to the
stepChildren
array of the parent view.
To ensure that the
stepChildren
array is in RAM, use this code:
if not HasSlot(self, 'stepChildren) then
self.stepChildren := Clone(self.stepChildren);
AddArraySlot(self.stepChildren,
myDynamicTemplate
);
The
if
statement checks whether the
stepChildren
slot already exists in the
current view (in RAM). If it does not, it is copied out of the template (in ROM)
into RAM. Then the new template is appended to the array.
All of this takes place in the
ViewSetupChildrenScript
method of the parent
view, which is before the
stepChildren
array is read and the child views are
created.
© 2007-2017, o7 studio » при воспроизведении материала сайта ссылка обязательна