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: Files /
Chapter 4 - Alias Manager / Using the Alias Manager


Maintaining Alias Records

You can store alias records as resources of type 'alis'.

CONST
   rAliasType = 'alis'; {resource type for saved alias records}
To store and retrieve resources, use the standard Resource Manager functions (AddResource, GetResource, and GetNamedResource) described in the chapter "Resource Manager" in Inside Macintosh: More Macintosh Toolbox. Listing 4-2 illustrates one way to save an alias record as a resource in a document file's resource fork.

Listing 4-2 Storing an alias record as a resource

FUNCTION DoSaveAlias (myDoc: FSSpec; myAliasHdl: AliasHandle): OSErr;
VAR
   myErr: OSErr;
   myFile: Integer;           {file ref number of document's resource fork}
CONST
   kID = 129;
   kName = 'Dictionary Alias';
BEGIN
   myFile := FSpOpenResFile(myDoc, fsCurPerm);
   IF myFile = -1 THEN        {couldn't open the document's resource fork}
      BEGIN
         DoSaveAlias := ResError;
         exit(DoSaveAlias);
      END;
   AddResource(Handle(myAliasHdl), rAliasType, kID, kName);
   myErr := ResError;         {check for errors adding resource}
   IF myErr = noErr THEN
      BEGIN
         WriteResource(Handle(myAliasHdl));
         myErr := ResError;   {check for errors writing resource}
      END;
   DoSaveAlias := myErr;
END;
Note that DoSaveAlias assumes that the file specified by the myDoc parameter already has a resource fork and that the file is not yet open. Your application might have different requirements.

To update an alias record, use the UpdateAlias function. You typically call UpdateAlias any time you know that the target of an alias record has been renamed
or otherwise changed. You are most likely to call UpdateAlias after a call to the MatchAlias function. If MatchAlias identifies a single target, it sets a flag telling
you whether or not the key information about the target file matches the information in the alias record. It is the responsibility of your application to update the record.

The ResolveAlias function automatically updates an alias record if any of the key information about the identified target does not match the information in the record.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996