C H A P T E R 3
Showing a Hidden View
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
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
flag in the
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
message using the name
under which you have declared it (for example,
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:
. You can also set
values in a declared view before sending it the
Adding to the stepChildren Array
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
array of the parent view using the
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
its parent view, you add this frame to the
array of the parent view.
To ensure that the
array is in RAM, use this code:
if not HasSlot(self, 'stepChildren) then
self.stepChildren := Clone(self.stepChildren);
statement checks whether the
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
method of the parent
view, which is before the
array is read and the child views are