test




-----Original Message-----
From: Chris Tutty [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 14, 2004 7:21 PM
To: Palm Developer Forum
Subject: Re: String values concatenating

From: "Ben Combee" <[EMAIL PROTECTED]>
> At 02:54 PM 4/14/2004, you wrote:
> >I have a field on a form that I want to fill in with a value the user
> >selects from a List Item in a popup trigger.
>
> Is this a read-only field?  If so, see the recipe at
>
http://www.palmos.com/dev/support/docs/recipes/fields_with_static_text.html
> for some ideas.  For a modifiable field, you can use similar code, but you
> need to manage the field's text handle, carefully acquiring it, unlocking
> it, resizing it, locking it, setting the new test, and giving the handle
> back to the field.
>
You mean a function like the one below?  I've been using it for years
so it's probably overdue for a code review.

Is there a shared area we can build up a library of this sort of function?
Or would inconsistencies in naming style and 'discussions' about brace
layout bury any benefit?   :-)

Chris Tutty

/** Set the contents of a field to the passed string

You will need to call FldDrawField or FrmDrawForm
following this to see the change.

@param fldP - a pointer to the field to be altered.
@param text - a pointer tothe string that will replace the
    contents of the field.  This is copied to the field's
    buffer so can be discarded when this function returns.
    Can be NULL, in which case the field will be cleared.
*/
void SetFieldText(FieldType * fldP, char * text)
{
 MemHandle hMem = NULL;

 if (!fldP)
  return;

 if (!text)
 {
  FldFreeMemory(fldP);

 } else
 {
  char * pMem = NULL;

#ifdef DEBUG
  ErrFatalDisplayIf (textLen > FldGetMaxChars (fldP),
      "SetFieldText - too long!");
#endif

  MemHandle hMem = FldGetTextHandle(fldP);
  if (!hMem)
  {
   // enlarge ready to copy text below
   hMem = MemHandleNew(StrLen(text) + 1);

  } else
  {
   // Disconnect from the field (unlocks)
   FldSetTextHandle(fldP, NULL);

   // Check for size?
   if (MemHandleSize(hMem) > StrLen(text))
   {
    ; // ok - ready for copy below

   } else
   {
    // enlarge ready to copy text below
    Err err = MemHandleResize(hMem, StrLen(text) + 1);
   }
  }

  if (hMem)
  {
   pMem = MemHandleLock(hMem);
   StrCopy(pMem, text);
   MemHandleUnlock(hMem);
   FldSetTextHandle(fldP, hMem);
  }
 } // end if (text)
}



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