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: Interapplication Communication /
Chapter 6 - Resolving and Creating Object Specifier Records / Writing Object Accessor Functions


Writing Object Accessor Functions That Find Properties

The Apple event object to which a property belongs is that property's container. Your application should provide an object accessor function for finding properties in containers identified by tokens of various descriptor types. Your application does not need to be given a property's specific object class in order to find that property; instead, you can specify the object class ID for any property with the constant cProperty. Thus, you can write a single object accessor function that can find any property of an object identified by a token of a given descriptor type.

To install such an object accessor function, you can add a single entry to the object accessor dispatch table that specifies the desired object class as cProperty for a given token descriptor type. For example, Listing 6-9 shows an object accessor function that identifies any property of a window.

Listing 6-9 An object accessor function that identifies any property of a window

FUNCTION MyFindPropertyOfWindowObjectAccessor 
                              (desiredClass: DescType; 
                              containerToken: AEDesc; 
                              containerClass: DescType;
                              keyForm: DescType; keyData: AEDesc;
                              VAR token: AEDesc; 
                              theRefCon: LongInt): OSErr;
VAR
   theProperty: DescType;
BEGIN
   MyFindPropertyOfWindowObjectAccessor := noErr;
   MyGetPropFromKeyData(keyData, theProperty);
   IF keyForm = formPropertyID THEN
   BEGIN
      IF theProperty = pName THEN
         {create token that identifies name property of the }
         { window}
         MyCreateToken(typeMyWindowProp, containerToken, pName, 
                        token)
      ELSE
      IF theProperty = pBounds THEN
         {create token that identifies bounds property of the }
         { window}
         MyCreateToken(typeMyWindowProp, containerToken, pBounds, 
                        token)

      {create tokens for other properties as appropriate}

      ELSE
         MyFindPropertyOfWindowObjectAccessor := 
                                          kErrorPropNotFound;
   END
   ELSE
      MyFindPropertyOfWindowObjectAccessor := 
                                          kKeyFormNotSupported;
END; 
The MyFindPropertyOfWindowObjectAccessor function takes a token that identifies a window and creates a token that identifies the requested property of that window. See Figure 6-6 on page 6-46 for an illustration of the logical organization of a token of descriptor type typeMyWindowProp.

This simplified example merely translates information about the requested property and the window to which it belongs into the form of a token of type typeMyWindowProp. This token can then be used by Apple event handlers to identify the corresponding window and its property, so that a handler can either retrieve the value of the property (for example, a Get Data handler) or change the value of the property (for example, a Set Data handler). Like other tokens, a token that identifies a property should always contain a reference to the corresponding property and the object to which it belongs--not a copy of the data for that object's property.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996