Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 3 - Values / Value Class Definitions


Reference

A value of class Reference is a reference to an object. You can create a value of class Reference by using the A Reference To operator. In addition, applications can return references in response to commands.

A value of class Reference is different from the value of the object to which a reference refers. For example, the reference

word 1 of front window of app "Scriptable Text Editor"
--result: a string
refers to a word object, whose value is a string, such as "Today". But a value of class Reference created with the A Reference To operator is a structure within AppleScript that refers (or points) to a specific object.

a reference to word 1 of front window of app �
   "Scriptable Text Editor"
--result: word 1 of window 1 of application �
   "Scriptable Text Editor"
The difference between a value of class Reference and the object it refers to is analogous to the difference between an address and the building it refers to. The address is a series of words and numbers, such as "1414 Maple Street," that identifies the building. It is distinct from the building itself.

Values of class Reference are similar to pointers in other programming languages, but unlike pointers, references can refer only to objects. For more information about creating values of class Reference, see "The 'A Reference To' Operator" on page 153.

LITERAL EXPRESSIONS
word 1 of document "Report"
window "Graph"
PROPERTIES
Class
The class identifier for the object. This property is read-only, and its value is always reference.
Contents
The value of the object to which the reference refers. The class
of the value depends on the reference. For information about how to use the Contents property, see "The 'A Reference To' Operator" on page 153.
ELEMENTS
None

OPERATORS
The A Reference To operator returns a reference as its result.

COERCIONS SUPPORTED
The application to which an object specified by a reference belongs determines whether the value of the object can be coerced to a desired class.

NOTES
A reference can function as a reference to an object or as an expression whose value is the value of the object specified in the reference. When a reference is the direct parameter of a command, it usually functions as a reference to an object, indicating to which object the command should be sent. In most other cases, references function as expressions, which AppleScript evaluates by getting their values.

For example, the reference in the following example functions as a reference to an object. It identifies the object to which the Copy command is sent.

copy word 1 of front document of application "Scriptable Text Editor"
On the other hand, the reference in the following example functions as a reference expression:

repeat (word 1 of front document of application ÿ
   "Scriptable Text Editor") times
      display dialog "Hello"
end repeat
When AppleScript executes the statement, it gets the value of the reference word 1 of front document of application "Scriptable Text Editor"--a string--and then coerces it to an integer, if possible. (For information about the Repeat statement, see "Repeat Statements," which begins on page 194. For information about coercions, see "Coercing Values" on page 66.)


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996