Why using STATIC variable for the label text?  If CtlGetLabel() returns a
pointer to the label text, I should be able to get the text whenever I
want.  Right?

-Elizabeth


                                                                                       
                          
                    Igor Mozolevsky                                                    
                          
                    <[EMAIL PROTECTED]>                 To:     Palm Developer 
Forum                         
                    Sent by:                                
<[EMAIL PROTECTED]>                     
                    bounce-palm-dev-forum-8072@news.        cc:                        
                          
                    palmos.com                              Subject:     RE: Question 
on CtlGetLabel()           
                                                                                       
                          
                                                                                       
                          
                    08/07/01 05:38 PM                                                  
                          
                    Please respond to Palm Developer                                   
                          
                    Forum                                                              
                          
                                                                                       
                          
                                                                                       
                          






--On 07 August 2001 16:34 -0700 [EMAIL PROTECTED] wrote:

>
> No.  I was trying to get the label text from a Selector control and save
> it to a char* variable.  Here is a copy of the comments from the API
> Reference documentation about using CtlSetLabel...
>
> This function stores the newLabel pointer in the control's data
structure.
> It doesn't make a copy of the string that is passed in.
> Therefore, if you use CtlSetLabel, you must manage the string yourself.
> You must ensure that it persists for as long as it is being displayed
> (that is, for as long as the control is displayed or until you call
> CtlSetLabel with a new string), and you must free the string after it is
> no longer in use (typically after the form containing the control is
> freed).
> If you never use CtlSetLabel, you do not need to worry about freeing a
> control's label.
>
> Can you send me lines of code to do a CtlSetLabel() and save the label to
> a char* variable using the string handle returned from CtrGetLabel()?

{
 // MAKE SURE THEY ARE STATIC!!!
 static Char *newLabel;
 static Char *oldLabel;

 oldLabel = CtlGetLabel(...); // If you really need it...
 newLabel = MemPtrNew(StrLen(newLabelText)+1);
 StrCopy(newLabel, newLablelText);
 CtlSetLabel(...newLabel); // NB: new label should not be longer that old
label
 // Vola!!!
}

There are a few possible memory leaks in the above code, I couldn't be
bothered to insert the whole lot. There is a way of cleaning up from the
same function after you're done with the form... Keep that as an exercise
to the reader :-)

IM :-)

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





-- 
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