[comp.sys.mac.programmer] GetIndString, where is the reverse?

cpyang@ccnysci.UUCP (Chao Ping Yang) (11/22/88)

   I am keeping a lot of strings in resources and I need to update
them when running my program, but how do I change resource data?
Or how do I do the reverse of GetIndString?  All I can find from
the Toolbox routines are handles to the resource and the structures
of the resource files, but that look like a lot of work.

Can somebody help me on this?  This newsgroup has been very helpful.

==Chaoping

drc@claris.com (Dennis Cohen) (11/22/88)

In article <1012@ccnysci.UUCP> cpyang@ccnysci.UUCP (Chao Ping Yang) writes:
>
>   I am keeping a lot of strings in resources and I need to update
>them when running my program, but how do I change resource data?
>Or how do I do the reverse of GetIndString?  All I can find from
>the Toolbox routines are handles to the resource and the structures
>of the resource files, but that look like a lot of work.
>

One way to do this is to call GetResource, DetachResource, RmveResource,
AddResource, and UpdateResFile with the appropriate arguments.  You
recognize correctly that it is a lot of work.

You don't need to know the structures of the resource files, but you do need,
occasionally, to know the structures of the resource types to modify them
correctly.  For example, if you are modifying a string somewhere in the
middle of an STR#, be sure that you move everything after it to correctly
adjust to the new length.

The safest method is to create a handle to a new item, build your resource
in it, and then add it to the resource file (after removing the one that it
replaces).  Be sure to check your error returns at all points through this
process.

Best of luck,
Dennis Cohen
Claris Corp.
------------
Disclaimer:  Any opinions expressed above are _MINE_!

rick@Jessica.stanford.edu (Rick Wong) (11/23/88)

In article <7010@claris.com> drc@claris.com (Dennis Cohen) writes:
>In article <1012@ccnysci.UUCP> cpyang@ccnysci.UUCP (Chao Ping Yang) asks:
>>
>>	[How do you set a string in a string-list resource?]
>>
>
>One way to do this is to call GetResource, DetachResource, RmveResource,
>AddResource, and UpdateResFile with the appropriate arguments.
>
>		. . . if you are modifying a string somewhere in the
>middle of an STR#, be sure that you move everything after it to correctly
>adjust to the new length.
>
>The safest method is to create a handle to a new item, build your resource
>in it, and then add it to the resource file (after removing the one that it
>replaces).  Be sure to check your error returns at all points through this
>process.
>

An easier method is to use everybody's favorite trap, Munger, which will
correctly adjust the location of all following strings.  To make sure the
Munger call succeeded, you can call GetHandleSize before and after to see
if the final handle size is what you expected.

In case you need to know the format of a 'STR#' resource, it's a two-byte
integer indicating the number of strings, followed by Pascal-format strings.
Since the strings can have different lengths, you'll have to do some pointer
arithmetic to access a particular string.  If you are at a string, you can
get to the next one by adding the string's length byte to the current value
of your pointer.  Be sure to treat the length byte as an unsigned value.

>Dennis Cohen

Rick Wong
Courseware Authoring Tools Project, Stanford University

beard@ux1.lbl.gov (Patrick C Beard) (11/26/88)

In article <1012@ccnysci.UUCP> cpyang@ccnysci.UUCP (Chao Ping Yang) writes:
>
>   I am keeping a lot of strings in resources and I need to update
>them when running my program, but how do I change resource data?
>Or how do I do the reverse of GetIndString?  All I can find from
>the Toolbox routines are handles to the resource and the structures
>of the resource files, but that look like a lot of work.
>
>Can somebody help me on this?  This newsgroup has been very helpful.
>
>==Chaoping

Usually, all I do to change a resource is get the handle to the data,
make the changes, and then call ChangedResource(handle).  This tells
the resource manager that your resource has changed and should be updated. 
Then call UpdateResFile(refNum).

I hope this helps.

Patrick Beard
Lawrence Berkeley Laboratory

ts@cup.portal.com (Tim W Smith) (12/11/88)

Or you could do this, assuming you have another Mac available
and that the other Mac is running TOPS and Timbukto (sp?).

	1. Write the STR# resource to a file

	2. Send it over to the other Mac using TOPS

	3. Use Timbukto to open the file on the other Mac
	with ResEdit

	4. Make your changes using ResEdit via Timbukto

	5. Copy the file back via TOPS.

As they say, why re-invent the wheel? :-)