beautypg.com

Apple Newton Programmer’s Newton 2.0 (for Newton 2.0) User Manual

Page 458

background image

C H A P T E R 1 1

Data Storage and Retrieval

11-26

Using Newton Data Storage Objects

This section presumes understanding of the material in “About Data Storage on
Newton Devices” beginning on page 11-1.

Most applications store data as frames that reside in soup entries. You can create a
frame by simply defining it and saving it in a variable, a constant, or a slot in
another frame. For example, the following code fragment defines a frame
containing the

aSlot

and

otherSlot

slots. The frame itself is stored in the

myFrame

variable. For all practical purposes you can treat variables that hold

NewtonScript objects as the objects themselves; hence, the following discussion
refers to the frame saved in the

myFrame

variable as the

myFrame

frame.

myFrame := {aSlot: "some string data", otherSlot: 9258};

The

myFrame

frame contains two slots: the

aSlot

slot stores the

"some

string data"

string and the

otherSlot

slot stores the

9258

integer value.

Because every NewtonScript object encapsulates its own class data, you need not
declare types for NewtonScript data structures, including slots.

Frames are not persistent unless stored as soup entries. To add the

myFrame

frame

to a soup, you must send a message to the appropriate soup object. You can obtain
a soup or union soup object by creating a new one or by retrieving a reference to
one that is already present.

To create a new union soup, use the

RegUnionSoup

function to register its soup

definition with the system. The system uses this definition to create the union’s
member soups as needed to store soup entries.

The following code fragment saves the union soup object

RegUnionSoup

returns

in the

myUSoup

local variable. You might place code like this example in your

application (

form

) part’s

InstallScript

function or your application base

view’s

ViewSetupFormScript

method:

local aSlotIndexSpec := {structure: 'slot, path: 'aSlot,

type: 'string};

local otherSlotIndexSpec := {structure: 'slot, path: 'otherSlot,

type: 'int};

local mySoupDef := {name: "mySoup:mySig",

userName: "My Soup",

ownerApp: '|MyApp:MySig|,

ownerAppName : "My Application",

userDescr: "This is the My Application soup.",

indexes: [aSlotIndexSpec,otherSlotIndexSpec]

};

local myUsoup := RegUnionSoup('|MyApp:MySig|,mySoupDef);

Note the use of the

mySig

developer signature as a suffix to ensure the uniqueness

of the values of the

name

and

ownerApp

slots. For more information regarding

developer signatures, see Chapter 2, “Getting Started.”