At 12:00am -0700 00-09-22, Palm Developer Forum digest wrote:
>Subject: RE: strings and string lists
>From: Steve <[EMAIL PROTECTED]>
>Date: Thu, 21 Sep 00 11:54:18 -0700
>X-Message-Number: 31
>
>  >If you're getting a lot of strings, then option 3 is to write two
>  >utility routines, in which case it takes 16 bytes of code per string
>  >usage.
>  >
>  >    const Char* someString = GetAndLockStringResource(1000);
>  >    <use the string>
>  >    ReleaseLockedStringResource(someStringP);
>
>Actually all you need is ONE routine, like this:
>
>StrCopyFromResource(myString,1000)
>
>which gets the string, copies it into your own string variable (which can
>be located anyplace), and then releases the resource. Obviously this
>means that "myString" always has to be larger than the largest possible
>string being read from a resource, but that's usually no problem to
>arrange. Doing this with one routine instead of two makes the code for
>the rest of the app that much cleaner.

This can be used as a simpler way of loading strings - but there are 
two limitations that I've run into with this approach in the past:

1. Since the Palm OS stack is small, you don't want to create local 
string variables that are significantly bigger than they need to be. 
However the length of the string data can be dramatically different, 
depending on the target language for localization. So determining a 
safe, yet not excessive, max size for each string resource is tricky.

2. For strings that need to exist beyond the scope of the current 
routine, local variables aren't an option. A common example is 
FrmSetTitle(), where the string has to stick around for the duration 
of the form. You can use a global variable, unless you've got a form 
that can be displayed as a result of a sub-launch.

As Dave Johnson pointed out, SysStringByIndex is a handy utility 
routine for loading strings from a string list, but it requires you 
to use a string variable to save the result.

-- Ken

Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to