View System and Messages

Declaring Views

In NewtonScript, children inherit from parents, but parents don't inherit from children (as in real life).

Parent inheritance gives children access to slots in their ancestors--they can send messages to ancestors or access their data. Parents, on the other hand, can't easily access slots from or send messages to their children (also as in real life).

Of course, you can access a child from a parent by using the ChildViewFrames message (this returns an array of children). But these children do not have names so it is difficult to send them messages. (It's as if the parents never named their children, referring only to them as the first child, the second child, and so on.)

Declaring a view to its ancestor provides a name for the child that can be used by that ancestor. Declaring a child view to an ancestor creates a slot in that ancestor whose value is the child view. Having done this, the ancestor can access slots from and send messages to the child using the child's name.


Note:This is a straightforward operation in NTK and is described in "Using Declare To on a Template" on page 397.


Declaring a child to an ancestor in NTK does not create the slot with the child's name in the template. It is not until you get to the Newton, where views exist, that such named slots exist. What NTK does do is save information about declared views in the template. When the ancestor view is opened (in response to an Open message), the view system creates the view for the child and creates a slot in the parent to point to that child. The slot is set to nil when the ancestor is closed, but as long as the ancestor is open, the declared view exists.

Sibling Messages and Declaring
Invisible Views
Don't Declare All Views
Application Base View

An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996