Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!wuarchive!zaphod.mps.ohio-state.edu!rpi!uwm.edu!linac!att!cbnewsl!cbnewsk!ech From: ech@cbnewsk.att.com (ned.horvath) Newsgroups: comp.sys.mac.programmer Subject: Re: Problem with GetString? Or is it me? Message-ID: <1991Jan16.201312.3794@cbnewsk.att.com> Date: 16 Jan 91 20:13:12 GMT References: <1991Jan16.020012.24103@trl.oz.au> Organization: AT&T Bell Laboratories Lines: 30 From article <1991Jan16.020012.24103@trl.oz.au>, by summer@sarcasm.trl.oz.au (Mark Summerfield): ... > if ((theString = GetString(strID)) == nil) { > /* Handle missing resource case... */ > } > HLock(theString); > ParamText(*theString, nil, nil, nil); ... [display alert] > HUnlock(theString); /* Probably unnecessary */ > DisposHandle(theString); ... > This works fine the first time I use it for any given strID, the problem > is that if it is called a second time (at any later stage) with a strID > that has been used before (ie if the same error occurs twice) then the > handle returned by GetString() points to an empty string! I've checked this > with SADE -- I'm not just guessing from the empty dialog box :-) DON'T use DisposHandle -- this is a resource, so use ReleaseResource to indicate you're done with it. Incidentally, ParamText makes a copy, so you can HUnlock and ReleaseResource immediately after the ParamText call -- you don't have to keep it around for the Alert. Also, you might want to call LoadResource right after GetString: it's possible that the handle for the string is in memory, but the contents have been purged. LoadResource does nothing if the content is present, and loads the content if it isn't, so the call is cheap insurance. =Ned Horvath= ehorvath@attmail.com