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: Text /
Chapter 8 - Dictionary Manager / Using the Dictionary Manager


Making a Dictionary

You make a new dictionary by first creating a file and then initializing it as a Dictionary Manager dictionary.

Creating the File

To create a dictionary file, you first use a File Manager function such as FSpCreate
or HCreate to create a file. Listing 8-1 is a sample routine that creates a file for a
user dictionary.

Listing 8-1 Creating a dictionary file

FUNCTION CreateUserDictionary (VAR dictionaryFSSpec: FSSpec; 
                              creator, fileType: OSType; 
                              script: ScriptCode): OSErr;
VAR
   err: OSErr;
   fileReply: StandardFileReply;
BEGIN
   err := noErr;

   {get dictionary name and filespec}
   StandardPutFile('Create empty dictionary as...', 
                  'UserDictionary', fileReply);
   {delete existing dictionary if user OKs it}
   IF fileReply.sfGood THEN BEGIN
      dictionaryFSSpec := fileReply.sfFile;
      IF fileReply.sfReplacing THEN
         err := FSpDelete(dictionaryFSSpec);
      {create the empty dictionary file}
      IF err = noErr THEN BEGIN
         err := FSpCreate(dictionaryFSSpec, creator, 
                           fileType, script);
         IF err <> noErr THEN
            DebugErrStr(err, 'FSpCreate');{handle error here}
      END
      ELSE
         DebugErrStr(err, 'FSpDelete');   {handle error here}
   END
   ELSE
      err := fnfErr;                      {assign error}
   CreateUserDictionary := err;
END;     {CreateUserDictionary}

Constructing the Dictionary

To make the internal structure of your newly created dictionary file, you use the InitializeDictionary function. You provide a file system specification pointer to the file you just created, you specify what maximum size the dictionary keys can have, and you can specify what search criteria--such as case-sensitivity--the dictionary
will support.

The following code is a statement that initializes a dictionary file. It uses an application-defined constant (kMaximumKeyLength) to specify key length, an application-defined global (gDictionaryScriptID) to specify the script system for the dictionary, and the kIsCaseSensitive constant to specify that searches are to be case-sensitive.

err := InitializeDictionary(dictionaryFile, kMaximumKeyLength, 
                            $1000 + kIsCaseSensitive, 
                            gDictionaryScriptID);

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996