Chapter 4 Using Activities in ADL

4.4 NROs Derived from System-defined NROs

AM2 also comes with a library of special-purpose NROs that you can use in ADL programs. Unlike the system-defined (or wrapped class) NROs described in Section 4.2, "Using Notification Request Objects" page 62 and Section 4.3, "Using Other Types of System-defined NRO Classes" page 64, these library NROs are written in the ADL. They are classes derived from the Nro wrapped class. You can use them by including the file nro.adl in the standard ADL library.

One such NRO is the vanillaNro class. This NRO sends only the client data in its messages. For example, suppose we want to simplify our mouse tracking program shown above so that it only reports the type of the last mouse action, not the location. In this case, the (x,y) coordinates of the mouse activity are not needed. We could instead use three instances of the vanillaNro object defined as follows:

   vanillaNro {'Create, 'MouseDown, self, 'MouseTrack,
      "Down"} => downNro;
   vanillaNro {'Create, 'MouseUp, self, 'MouseTrack,
       "Up"} => upNro;
   vanillaNro {'Create, 'MouseMove, self, 'MouseTrack,
       "Move"} => moveNro;
We can then rewrite the MouseTrack method as show in Figure 4.6.
New Version of MouseTrack Method Using vanillaNros
on MouseTrack: string clientData

{

reportLabel.label = "Mouse" & clientData & "activity";

}

An even simpler NRO available in the standard library that sends no arguments when an event triggers the activity. This is the simpleNro class. Any method that handles an activity subscribed to using a simpleNro must have no arguments.

For example, we could rewrite the mouse tracking program in Figure 4.6 so that each of the three activities being subscribed to send a message to a different method. In this case, we could use the simpleNro class instead of the vanillaNro class, as follows:

   simpleNro {'Create, 'MouseDown, self, 'MousePush,
	     ""} => downNro;
   simpleNro {'Create, 'MouseUp, self, 'MouseRelease,
       ""} => upNro;
   simpleNro {'Create, 'MouseMove, self, 'MouseChange,
       ""} => moveNro;
In this case, the method named MouseTrack shown in Figure 4.6 would be replaced by three simpler methods named MousePush, MouseRelease and MouseChange,as shown in Figure 4.7.
Methods Using simpleNro Objects
on MousePush

{

reportLabel.label = "Mouse down activity";

}

on MouseRelease

{

reportLabel.label = "Mouse up activity";

}

on MouseChange

{

reportLabel.label = "Mouse move activity";

}


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker