Subject: RE: Checking to see if field has data in it before passing it routine
From: "Jonathan King" <[EMAIL PROTECTED]>
Date: Sat, 23 Jul 2005 18:41:31 -0400
X-Message-Number: 11

Here is a simple way to do what you are doing.

static void GetFieldData( UInt16 fld, Char *text ) {
        FormPtr     frm = FrmGetActiveForm();
        FieldPtr    fldP = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,fld));

        if(FldGetTextLegnth(fldP))  {
                StrCopy(text, FldGetTextPtr(fldP);
        }
}

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:

  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) return false; // I like error checking !!
        if (FldGetTextLength (pField))
                StrNCat (text, FldGetTextPtr (pField), maxLen);
        return true;
  }

Roger Stringer
Marietta Systems, Inc. (www.rf-tp.com)


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

Reply via email to