Important: The information in this document is obsolete and should not be used for new development.
OSACompile
You can use theOSACompilefunction to compile the source data for a script and obtain a script ID for a compiled script or a script context.
FUNCTION OSACompile (scriptingComponent: ComponentInstance; sourceData: AEDesc; modeFlags: LongInt; VAR previousAndResultingScriptID: OSAID) : OSAError;
scriptingComponent- A component instance created by a prior call to the Component Manager function
OpenDefaultComponentorOpenComponent(see page 10-4).sourceData- A descriptor record containing suitable source data for the specified scripting component.
modeFlags- Information used by individual scripting components. To avoid setting mode flag values, specify
kOSAModeNull. Other possible mode flags are listed in the description that follows.previousAndResultingScriptID- The script ID for the resulting compiled script. If the value of this parameter on input is
kOSANullScript,OSACompilereturns a new script ID for the compiled script data. If the value of this parameter on input is an existing script ID,OSACompileupdates the script ID so that it refers to the newly compiled script data.DESCRIPTION
You can pass a descriptor record containing source data suitable for a specific scripting component (usually text) to theOSACompilefunction to obtain a script ID for the equivalent compiled script or script context. To compile the source data as a script context for use withOSAExecuteEventorOSADoEvent, you must set thekOSACompileIntoContextflag, and the source data should include appropriate handlers.After you have successfully compiled the script, you can use the returned script ID to refer to the compiled script when you call
OSAExecuteand other scripting component routines.You can control the way a compiled script is executed by adding any of these flags to the
modeFlagsparameter:
Flag Description kOSAModePreventGetSource Compiled script consists of only the minimum script data required to run the script. It will cause an error if passed to OSAGetSource.kOSACompileIntoContext The OSACompilefunction returns a script context instead of a compiled script.kOSAModeAugmentContext Script data associated with script ID passed in previousAndResultingCompiledScriptIDis augmented rather than replaced with the new compiled script. Specifying this flag automatically invokes thekOSAModeCompileIntoContextmode flag. If you redefine variables, handlers, and so on that were previously defined in the script context, the new definitions will replace the old ones.kOSAModeNeverInteract Adds kAENeverInteracttosendModeparameter ofAESendfor events sent when script is executed.kOSAModeCanInteract Adds kAECanInteracttosendModeparameter ofAESendfor events sent when script is executed.kOSAModeAlwaysInteract Adds kAEAlwaysInteracttosendModeparameter ofAESendfor events sent when script is executed.kOSAModeDontReconnect Adds kAEDontReconnecttosendModeparameter ofAESendfor events sent when script is executed.kOSAModeCantSwitchLayer Prevents use of kAECanSwitchLayerinsendModeparameter ofAESendfor events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).kOSAModeDoRecord Prevents use of kAEDontRecordinsendModeparameter ofAESendfor events sent when script is executed (the opposite of the Apple Event Manager's interpretation of the same bit).SPECIAL CONSIDERATIONS
If you useOSACompilewith an instance of the generic scripting component and passkOSANullScriptin thepreviousAndResultingScriptIDparameter, the generic scripting component uses the default scripting component to compile the script.If you're recompiling a script, specify the original script ID in the
previousAndResultingScriptIDparameter. The generic scripting component uses the script ID to determine which scripting component it should use to compile the script.RESULT CODES
SEE ALSO
For an example of the use ofOSACompileto update an existing script ID, see Listing 10-5 on page 10-18. For an example of the use ofOSACompileto obtain a new script ID, see Listing 10-2 on page 10-9.For more information about the default scripting component associated with any instance of the generic scripting component, see "Generic Scripting Component Routines," which begins on page 10-83.