Introduction to Protos

Proto Nuts and Bolts

It is quite simple to use protos in an application. During design, you select a proto in the NTK tool palette and then draw out a corresponding template in a layout window (see FIGURE 7.1). When you create this type of template, NTK adds an _proto slot to it that contains a pointer to the system or user proto it is based upon. At run time, the view that is created from the template inherits all of the proto's slots. These slots contain data values and/or methods from the proto via this pointer.

FIGURE 7.1 : Creating a view based upon a template based upon a proto.


NTK takes care of adding the proper slots to your template automatically. But you should remember that whether you use standard NewtonScript frame syntax or NTK's graphic slot editor, the effect of creating templates based on protos is the same. As you can see in FIGURE 7.2, the protoTextButton template, named myTextButton, contains four slots.

FIGURE 7.2 : A template based on a proto contains an _proto slot pointing to the proto.


Notice in FIGURE 7.2 that the _proto slot contains a reference to protoTextButton, the proto upon which it is based. You could also portray this same template in standard NewtonScript:

MyTextButton := {
	buttonClickScript: ...,
	text: "Button",
	viewBounds: ...,
	_proto: protoTextButton
}

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

Last modified: 1 DEC 1996