Jim, try this...

/////////////////////////////////////////////////////////////////////////////////////////////////
static MemHandle GetTextFromField(UInt16 controlID)
{
        FormType*               pForm;
        FieldType*              FieldPtr;
        MemHandle               h,      oldHandle;
        char*                   p;

        pForm = FrmGetActiveForm();
        FieldPtr = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, controlID));
        h = FldGetTextHandle(FieldPtr);
        if(h)
        {
                p = MemHandleLock(h);           // prevent the chunk from 
moving (lock) and obtain pointer to location
                if(p)
                {
                        MemHandleResize(h, StrLen(p)+1);
                }
                MemHandleUnlock(h);
        }
        return h;
}
/////////////////////////////////////////////////////////////////////////////////////////////////

~Tony


>>> [EMAIL PROTECTED] 02/10/05 07:54AM >>>
I am trying to build a function that will return the contents of a field 
(basic).  The trouble is that all the examples I have found are void 
functions that do not return anything.

Question #1: when I unlock the handle "h", does that invalidate the pointer 
to the text string so that it cannot be reliably returned?

Question 2: If that is the case, how do I work around it?

Thanks in advance.
Jim Haines


char *getFieldText(UInt16 fieldID)
{
FieldType *fldP;
MemHandle h;
char *field;

fldP=getObjectPtr(fieldID); //get a pointer to the field
if(FldGetTextLength(fldP)>0) // if there is something in the field
 {
 h=FldGetTextHandle(fldP); //get a handle to the edited text in the field
 if(h)
  {
  FldSetTextHandle(fldP,NULL); //disassociate the field and string
  field = MemHandleLock(h); // get the text and assign to "field"
  MemHandleUnlock(h); // unlock the handle to the chunk
  FldSetTextHandle(fldP,h); // assign the edited string to the field
  FldDrawField(fldP);  // write it back to the field
  }
 }
return field; // return the pointer to the edited chunk
}
Jim Haines 

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