Dina wrote:
I hv defined the resource string label with default
chars.
 But when i execute in Palm OS Simulator, I get the
error "Text in object is too long".
 When I execute the the prc file from Palm, It seems
to work for that form, but the app crashes when I
exit.
   Also there is no way to define the initial size of
the label.
  So what is the prblem in FrmCopyLabel?

As I understand it, basically FrmCopyLabel() works like this:

(1)  You open the form.  At this point the OS code reads the
     information describing your form out of a resource
     record in your app's PRC database.

(2)  The OS creates the form data structure.  It creates a
     buffer just large enough to hold the string that
     it finds for the label in the resource.

(3)  You then call FrmCopyLabel().  The string you pass as
     an argument is copied into the previously-allocated
     buffer.  On the debug ROM image (or the debug version
     of the Simulator), you get a warning if the string you
     passed is too large.  On release ROMs, probably no
     error checking is done, and it just overwrites the
     memory after the string.  This could very well be other
     form data structures, which could cause a crash when
     the OS tries to close the form and reads those structures.

As far as I can tell, there are only two ways to deal with this:

(1)  Make the label string large enough so that whatever string
     you need to set the label to is never longer than the label's
     initial string value as defined in the resource.  If necessary,
     you can use FrmGetLabel() and StrLen() at runtime (BEFORE
     changing the label) to find out the maximum string length
     you can set the label to.  Or, just remember the length
     you've set it to in the resource and remember never to write
     code that puts anything longer than that into the buffer.

     This approach seems very limited, but it could be helpful if
     you are using the label to draw a clock or something.  Then,
     if you are drawing just "HH:MM:SS PM", you know how big the
     buffer needs to be in advance, so you can just set your label
     to (say) "00:00:00 PM" in the resource in order to make the
     label buffer big enough.

(2)  Don't use a label.  Either just draw things yourself with
     WinDrawChars(), or use a field that's not editable and doesn't
     have an underline.

Hope that helps.

  - Logan

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

Reply via email to