beautypg.com

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

Page 633

background image

C H A P T E R 1 7

Additional System Services

Using Additional System Services

17-17

performing the

myFunc

function, pass it as the value of the

workFunc

parameter to

the

DoProgress

function, as illustrated in the following code fragment:

// options and data are accessible from workFunc because

// the workFunc "closes over" this context

myOpts := { wFnData:"Confabulating",

closebox:nil,

icon: kMyIcon,

statusText: kAppName,

gauge: 10,

titleText:"One moment, please."};

workFunc := func (theContextView)

begin

for x := 1 to 10 do

begin

myOpts.titleText:= :SomeWork(myOpts.wFnData);

myOpts.gauge := x * 10;

try

theContextView:SetStatus('vGauge,myOpts);

// handle any exceptions you anticipate

onexception |evt.ex.foo| do

// handle & possibly rethrow if it's fatal

onexception |evt.ex.bar| do

// handle & possibly rethrow if it's fatal

onexception |evt.ex| do

// either an unexpected exception has been

// thrown or the user has canceled our

// operation. Perform any cleanup

// necessary, and be sure to rethrow..

ReThrow();

end; // for loop

end; // workFunc

progress := DoProgress('vGauge, myOpts, workFunc);

if progress = 'cancelled then

// this is another place to clean up after being

// cancelled

The

workFunc

function’s argument,

theContextView

, is the status slip that

contains the gauge. A reference to this view is passed to your work function so that
you can send it

SetStatus

messages. Note that

workFunc

is structured in a way

that permits it to call the progress slip’s

SetStatus

method at regular intervals,

passing values used to update the progress slip’s gauge and message string.