Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!lts!amanda@lts.UUCP From: amanda@lts.UUCP (Amanda Walker) Newsgroups: comp.sys.mac.programmer Subject: Another toolbox gotcha Message-ID: <20-Apr-89.152339@192.41.214.2> Date: 20 Apr 89 19:17:57 GMT Sender: news@lts.UUCP Organization: InterCon Systems Corporation, Reston, VA Lines: 22 X-Posting-Front-End: Stop by Booth #329, MacWorld/Expo DC... This one isn't exactly a gotcha, but it is amusing enough that I thought I'd add it to the Toolbox War Stories :-). Rule: Always remove a resource before you replace it with something else. History: I had written a couple little routines that maintained a settings file, which had about three resources in it. To avoid leaving the resource file open for the life of the program, the "read" routine did a bunch of GetResources, detached the handles, and closed the resource file. The "write" routine opened the resource file, did a bunch of AddResources, and closed it. Seemed pretty simple. There's this note under "AddResource" that says you should make sure that another resource with the same ID. My mistake was in reading this as advice instead of literal truth. As it happens, the Resource Manager will quite happily give you as many resources with the same type and ID as you ask for, and "GetResource" will only find the first one, since it's the first in the resource map... The only way to access the others is to either give them different names or to access them as the nth resource of the given type instead of by ID. I discovered this when my settings file had grown to 150K...