I agree with Roger. I use CtlSetLabel a lot, and don't consider myself lucky that the apps don't crash. It just depends on what you want to achieve.

If you have a hard coded list of potential labels that might be displayed, and you simply want to select from that rigidly defined list, then it's pretty easy to make sure that the initial declaration is long enough. For this purpose the CtlSetLabel command requires the minimum of programming overhead.

If, on the other hand, you are allowing user input to define the text of the label, then maybe there will be an issue. By 'issue' I simply mean that more checks will have to be built into the code.

There are more ways than one of skinning a cat, with no particular method being entirely right or entirely wrong. (although, putting my Monty Python hat on for an instant, the 'safest' method would surely involve the cat being dead first ;) ).

Bob.


Roger Stringer wrote:

Luck has absolutely nothing to do with it.

To be able to safely dynamically write to a label, I take the following precautions
1) Put enough spaces in the initial label declaration to fill it out to a minimum of 12 characters
2) Use a "gatekeeper" function to change the label which ensures that the new string is never longer than 10 characters.
3) Don't change labels without going through this "gatekeeper" function.
4) When I need a longer text for a label, I use the alternative pointer method, but ensure I'm using a string that exists for the life of the form.


Note: The "10" limit works very well for me, but might not be the right maximum size for all.

Roger Stringer


Subject: Re: Re[2]: Dynamically rewriting a label
From: "Dave Lippincott" <[EMAIL PROTECTED]>
Date: Thu, 14 Oct 2004 09:18:16 -0400

You've been lucky. I had problems in past apps when modifying labels. If
you keep the new text to the same size or smaller then what was specified in
the resource editor, it should work. If you are building the new text
string based on inputs from the running app, make sure to test the string
length before stuffing into your label.
Its safer to use a read only edit field.


----- Original Message -----
From: "Martin Bruner" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Wednesday, October 13, 2004 6:24 PM
Subject: RE: Re[2]: Dynamically rewriting a label


> So far in my dozen or so released applications, this method has produced
no
> problems.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Adrien
> Regimbald
> Sent: Wednesday, October 13, 2004 3:55 PM
> To: Palm Developer Forum
> Subject: Re[2]: Dynamically rewriting a label
>
>
> Unfortunately, this is an error prone method. Modifying label text
> introduces ugly issues:
>
> * If you copy a "static string" to the label, you will have problems
> if the new string is longer than the text you put on the label within
> the original resource
> * If you copy a string variable to the label, you will need to ensure
> that the variable doesn't go out of scope. In C++, this isn't too bad
> with a class variable, but in C, you end up introducing undesirable
> global variables for every label





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

Reply via email to