From: "druid" <[EMAIL PROTECTED]>
> Here's a better way that has error checking, default processing and takes
> advantage of a unique feature of the PalmOS "StrNCat()" function to
prevent
> stack corruption:
>
Are you sure it's StrNCat you want and not StrNCopy? I'm just
asking because the old version copied to text so you seem to
have changed the way the function works.
> When using a functin like this where does the maxLen
> value come from when passing the data to this function
>
It depends on how the buffer is defined. If you're defining it
using a constant then pass that constant - 1. It gets more
complicated if you're building a string up and concatenating
because you need to take the existing length of the string into
account but for StrNCopy it's generally just a matter of passing
the defined length -1.
Chris Tutty
> Boolean GetFieldData (UInt16 fldNbr, Char *text, UInt16 maxLen) {
> FormPtr pForm = FrmGetActiveForm ();
> FieldPtr pField = FrmGetObjectPtr (pForm, FrmGetObjectIndex
> (pForm, fldNbr));
> if (text != NULL) *text = '\0'; // initialize
> if (text == NULL || pField == NULL)
> {
> missing_field = true;
> return false; // I like error checking !!
> } // use missing_field to set an aleart window and brake the
> file://static Boolean frmMain_saveButton_OnSelect(EventPtr event)
> // so as to not allow the save ??
> if (FldGetTextLength (pField))
> StrNCat (text, FldGetTextPtr (pField), maxLen);
> return true;
> }
>
>
> --
> For information on using the PalmSource Developer Forums, or to
unsubscribe, please see http://www.palmos.com/dev/support/forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/