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

If you get lucky, a release ROM may do what you intend if you hit one
of these snags, but if you try to debug your code with the emulator,
you'll probably get warnings, and if you get unlucky, your application
will choke on a user with some friendly message about pointers,
chunks, etc. followed by a reset.

At the end of the day, labels weren't really made for this purpose.
I'd recommend using a read only field instead. Write some wrapper
methods for getting/setting the text in fields, and then you'll just
need to use a one liner to set the text. Sure, it'll take some effort
to create your convenience methods at the start, but once you've done
it, it won't blow up in your face like the label method inevitably
will.

Adrien.

Wednesday, October 13, 2004, 2:50:53 PM, you wrote:

MB> Hi Adam

MB> This is the code I use to change a label text.  Text is just a null
MB> terminated character array.

MB> FormPtr frm = FrmGetActiveForm();
MB> UInt16 myLabelObjectIndex = FrmGetObjectIndex(frm,LabelID);
MB> FrmHideObject(frm,myLabelObjectIndex);
MB> FrmCopyLabel(frm,LabelID,Text);
MB> FrmShowObject(frm,myLabelObjectIndex);

MB> -----Original Message-----
MB> From: [EMAIL PROTECTED]
MB> [mailto:[EMAIL PROTECTED] Behalf Of
MB> Ornstein, Adam
MB> Sent: Wednesday, October 13, 2004 2:29 PM
MB> To: Palm Developer Forum
MB> Subject: Dynamically rewriting a label

MB> Can anyone point me toward a function that will allow me to redefine a
MB> labels text?

MB> Thanks



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


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

Reply via email to