Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 6 - Component Manager / Using the Component Manager


Using a Component

Once you have established a connection to a component, you can use its services.

Each time you call a component routine, you must specify the component instance that identifies your connection and provide any other parameters as required by the routine.

For example, Listing 6-4 illustrates the use of a drawing component. The application-defined procedure establishes a connection to a drawing component, calls the component's DrawerSetup function to establish the rectangle in which to draw the desired object, and then draws the object using the DrawerDraw function.

Listing 6-4 Using a drawing component

PROCEDURE MyDrawAnOval (VAR aDrawOvalComp: ComponentInstance);
VAR
   r:             Rect;
   result:        ComponentResult;
BEGIN
   {open a connection to a drawing component}
   aDrawOvalComp := OpenDefaultComponent('draw', 'oval');
   IF aDrawOvalComp <> NIL THEN
   BEGIN
      SetRect(r, 40, 40, 80, 80);      
      {set up rectangle for oval}
      result := DrawerSetup(aDrawOvalComp, r);
      IF result = noErr THEN           
         result := DrawerDraw(aDrawOvalComp);{draw oval}
   END;
END;
If you specify an invalid connection as a parameter to a component routine, the Component Manager sets the function result of the component routine to badComponentInstance.

Each component type supports a defined set of functions. You must refer to the appropriate documentation for a description of the functions supported by a component. You also need to refer to the component's documentation for information on the appropriate interface files that you must include to use the component (the interface files for the drawing component are shown beginning on page 6-27). As an example, drawing components support the following functions:

FUNCTION DrawerSetup(myInstance: ComponentInstance; 
                     VAR r: Rect): ComponentResult;
FUNCTION DrawerClick(myInstance: ComponentInstance; 
                     p: Point): ComponentResult;
FUNCTION DrawerMove (myInstance: ComponentInstance; x: Integer;
                     y: Integer): ComponentResult;
FUNCTION DrawerDraw (myInstance: ComponentInstance)
                     : ComponentResult;
FUNCTION DrawerErase(myInstance: ComponentInstance)
                     : ComponentResult;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996