Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!blkcat!f421.n109.z1.fidonet.org!Ken.Knight From: Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) Newsgroups: comp.sys.mac.programmer Subject: Re: How do you create new resources from within program? Message-ID: <3709.27CAE880@blkcat.fidonet.org> Date: 26 Feb 91 21:26:17 GMT Sender: ufgate@blkcat.fidonet.org (newsout1.26) Organization: FidoNet node 1:109/421 - The Twilight Clone, Paul Heller Lines: 52 jwinterm@jarthur.Claremont.EDU (Jim Wintermyre) writes >The data for a 'STR ' resource should be a Pascal string (length byte >at >beginning). The StringHandle data type (IM 1-78) is particularly >convenient >for adding resources of type 'STR '. The following code fragment >shows how >to add a resource of this type. First you set a variable of type >Str255 to >whatever it is you want to put into the resource. Then you can use >the >Toolbox Utilities function NewString (IM 1-468) to allocate space for >a >StringHandle to the string. A neat feature of this function is that >the >amount of space it allocates is determined by the length of the >string. So, >your resource won't take up 256 bytes when the string is only 2 >characters >long. > > procedure AddResStr; > var > theText: Str255; > myString: StringHandle; > resErr:integer; > begin > theText:= 'This is how you do it.' > myString := NewString(theText); > AddResource(Handle(myString), 'STR ', 200, 'String >Resource'); > resErr := ResError; > if resErr <> noErr then > DoResError; > end; {AddRes} > > [deleted] One thing to remember is that the resource isn't actually written out to the resource fork of the file until a _WriteResource, _CloseResFile, or _UpdateResFile call is made. If you many resources are being added it is probably a good idea to do an _UpdateResFile so that everything is saved. Also, AddResource will overwrite resources of the same type of there are ID conflicts. So, if you want to play it COMPLETELY safe calling _UniqueID isn't a bad idea. -- Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org via The Black Cat's Shack's FidoNet<->Usenet Gateway blkcat.fidonet.org and Fidonet 1:109/401