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 5 - Creating and Sending Apple Events / Creating an Apple Event


Adding Parameters to an Apple Event

You can use the AEPutParamPtr or AEPutParamDesc function to add parameters to an Apple event. When you use either of these functions, the Apple Event Manager adds the specified parameter to the Apple event.

Use the AEPutParamPtr function when you want to add data specified in a buffer as the parameter of an Apple event. You specify the Apple event, the keyword of the parameter to add, the descriptor type, a buffer that contains the data, and the size of this buffer as parameters to the AEPutParamPtr function. The AEPutParamPtr function adds the data to the Apple event as a parameter with the specified keyword.

For example, this code adds a parameter to the Multiply event using the AEPutParamPtr function:

CONST keyOperand1 = 'OPN1';
VAR
   number1:          LongInt;
   theAppleEvent:    AppleEvent;
   myErr:            OSErr;

number1 := 10;
myErr := AEPutParamPtr(theAppleEvent, keyOperand1, 
                       typeLongInteger, @number1,
                       SizeOf(number1));
In this example, the Apple Event Manager adds the parameter containing the first number to the specified Apple event.

Use the AEPutParamDesc function to add a descriptor record to an Apple event. The descriptor record you specify must already exist. To create or get a descriptor record, you can use the AECreateDesc, AEDuplicateDesc, and other Apple Event Manager functions that return a descriptor record.

When you create a descriptor record using the AECreateDesc function, you specify the descriptor type, a buffer that contains the data, and the size of this buffer as parameters. The AECreateDesc function returns the descriptor record that describes the data.

This example creates a descriptor record for the second parameter of the Multiply event:

VAR
   number2:          LongInt;
   multParam2Desc:   AEDesc;
   myErr:            OSErr;

number2 := 8;
myErr := AECreateDesc(typeLongInteger, @number2, SizeOf(number2),
                      multParam2Desc); 
In this example, the AECreateDesc function creates a descriptor record with the typeLongInteger descriptor type and the data identified in the number2 variable.

Once you have created a descriptor record, you can use AEPutParamDesc to add the data to an Apple event parameter. You specify the Apple event to add the parameter to, the keyword of the parameter, and the descriptor record of the parameter as parameters to the AEPutParamDesc function.

This example adds a second parameter to the Multiply event using the AEPutParamDesc function:

CONST keyOperand2 = 'OPN2';

myErr := AEPutParamDesc(theAppleEvent, keyOperand2, 
                        multParam2Desc);
This example adds the keyOperand2 keyword and the descriptor record created in the previous example as the second parameter to the specified Apple event.

You can also create a descriptor record without using Apple Event Manager routines. For example, this example generates an alias descriptor record from an existing alias handle:

WITH myAliasDesc DO
   BEGIN
      descriptorType := typeAlias;
      dataHandle := myAliasHandle;
   END;
Whatever method you use to create a descriptor record, you can add it to an Apple event parameter by using AEPutParamDesc.

After adding parameters to an Apple event, you can send the Apple event using the AESend function. See "Sending an Apple Event," which begins on page 5-13, for information about using this function.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996