Hi Micheal,
This is what I use, hope that helps, remember to free the memory when you go to
the next form.
tnn
/***************************************************************************/
/* */
/* FUNCTION: SetFieldText, taken from utils.c in SimpleScan example */
/* */
/* DESCRIPTION:Perform all necessary actions to set a Field control's */
/* text and redraw, if necesary. Allocates a text handle. */
/* */
/* */
/* PARAMETERS: nFieldID(in) - The resource ID of the field. */
/* pSrcText(in) - The text to copy into field. */
/* nMaxSize(in) - Max size that the field can grow. */
/* bRedraw(in) - Should the text be redrawn now? */
/* */
/* RETURNED: None */
/* */
/***************************************************************************/
void SetFieldText(UInt nFieldID, const CharPtr pSrcText, Int nMaxSize, Boolean
bRedraw)
{
VoidHand hFieldText;
CharPtr pFieldText;
FieldPtr pField;
Int16 len;
UInt32 curSize;
pField = (FieldPtr)GetObjectPtr(nFieldID);
if(!pField)
return;
hFieldText = FldGetTextHandle(pField);
if(!hFieldText) {
hFieldText = MemHandleNew(nMaxSize);
// If already allocated, make sure it can handle nMaxSize already.
// If not, realloc that buffer
} else {
curSize = MemHandleSize(hFieldText);
if(curSize < nMaxSize)
MemHandleResize(hFieldText, nMaxSize);
}
if( hFieldText ) {
len = StrLen(pSrcText);
pFieldText = (CharPtr)MemHandleLock(hFieldText);
if (len > nMaxSize) {
StrNCopy( pFieldText, pSrcText, nMaxSize-1);
pFieldText[nMaxSize-1] = nullChr;
} else {
StrCopy(pFieldText, pSrcText);
}
MemHandleUnlock(hFieldText);
FldSetTextHandle(pField,(Handle)hFieldText);
FldSetTextAllocatedSize(pField,nMaxSize);
FldSetMaxChars( pField, nMaxSize-1);
FldRecalculateField( pField, true );
if(bRedraw)
FldDrawField( pField );
}
}
/***************************************************************************/
/* FUNCTION: FreeFieldHandle, taken from SimpleScan example */
/* DESCRIPTION: Free the memory associated with the text field on the */
/* current Palm Form */
/* PARAMETERS: field id */
/* RETURNED: nothing */
/* */
/***************************************************************************/
void FreeFieldText(int objectID)
{
FieldPtr pField;
VoidHand textH;
pField = (FieldPtr)GetObjectPtr(objectID);
textH = FldGetTextHandle(pField);
if (textH){
FldSetTextHandle(pField, 0);
MemHandleFree(textH);
}
}
-----------------------------------------------
FREE! The World's Best Email Address @email.com
Reserve your name now at http://www.email.com
--
For information on using the ACCESS Developer Forums, or to unsubscribe, please
see http://www.access-company.com/developers/forums/