Important: The information in this document is obsolete and should not be used for new development.
Creating Alias Records
You create a new alias record by calling one of three functions:NewAlias,NewAliasMinimal, orNewAliasMinimalFromFullPath. TheNewAliasfunction creates a complete alias record that can make full use of the alias-resolution a gorithms. The other two functions are streamlined variations designed for circumstances when speed is more important than robust resolution services. All three functions allocate the memory for the record, fill it in, and return a handle to it.The
NewAliasfunction always records the name and the file or directory ID of the target, its creation date, the parent directory name and ID, and the volume name and creation date. It also records the full pathname of the target and a collection of other information. You can haveNewAliasstore relative path information as well by supplying a starting point for a relative path (see "Relative Searches" on page 4-5 for a description of relative paths).Call
NewAliaswhen you want to create an alias record to store for later use. For example, suppose you are writing a word-processing application that allows the user to customize a dictionary for use with a single text file. Your application stores the custom data in a separate dictionary file in the same directory as the document. As soon as you create the dictionary file, you can callNewAliasto create an alias record for that file, including path information relative to the user's text file. Listing 4-1 shows how to useNewAliasto create a new alias.Listing 4-1 Creating an alias record
FUNCTION DoCreateAlias (myDoc, myDict: FSSpec): OSErr; VAR myAliasHdl: AliasHandle; {handle to created alias} myErr: OSErr; BEGIN myErr := NewAlias(@myDoc, myDict, myAliasHdl); {create alias record} IF myAliasHdl <> NIL THEN myErr := DoSaveAlias(myDoc, myAliasHdl); {save it as a resource} DoCreateAlias := myErr; {return result code} END;The functionDoCreateAliasdefined in Listing 4-1 takes twoFSSpecrecords as parameters. The first specifies the document that is to serve as the starting point for a relative search, in this case the user's text file. The secondFSSpecrecord specifies the target of the alias to be created, in this example the dictionary file. TheDoCreateAliasfunction callsNewAliasto create the alias record; if successful, it calls the application- defined functionDoSaveAliasto save the alias record as a resource in the document file's resource fork. See Listing 4-2 on page 4-12 for a definition ofDoSaveAlias.The two variations on the
NewAliasfunction,NewAliasMinimalandNewAliasMinimalFromFullPath, record only a minimum of information about
the target. TheNewAliasMinimalfunction records only the target's name, parent directory ID, volume name and creation date, and volume mounting information. TheNewAliasMinimalFromFullPathfunction records only the full pathname of the target, including the volume name.Use
NewAliasMinimalorNewAliasMinimalFromFullPathwhen you are willing to give up robust alias-resolution service in return for speed. The Finder, for example, stores minimal aliases in the Apple events that tell your application to open or print a document. Because the alias record is resolved almost immediately, the description is likely to remain valid, and the shorter record is probably safe.You can use
NewAliasMinimalFromFullPathto create an alias record for a target that doesn't exist or that resides on an unmounted volume.