[EMAIL PROTECTED] wrote:
hi all
i am trying to set a text in the blank field(created first time in the application.)
i tried "FldSetTextPtr" which prefers the field should be "non-editable" . i
made it non-editable then this function sets the text.
but whenever i make it editable. and try to enter some value.
it gives me error --->
"Invalid field length".
i want to execute the field as -> it must have some default value , when the
application displays the field but the user can change it.
and later on that new value should remain in the field.
can anybody help me out????
This seems like a recurring question. I've used the following routine from Palm
for quite a while. Hope it helps you and many others.
--Mike Y.
/***********************************************************************
FUNCTION: SetFieldText()
DESCRIPTION:
Set a field with given text. Routine
appears in Palm's online training for Palm OS 5.0.
***********************************************************************/
void SetFieldText(FieldType *pFld, Char *pSrcStr, Boolean fDrawNow)
{
MemHandle hString;
UInt16 uwSize;
Char * pText;
// Clear field if passed a null pointer
if (!pSrcStr || !*pSrcStr) {
FldFreeMemory(pFld);
FldSetTextHandle(pFld, NULL);
// Draw field (only if form is already drawn)
if (fDrawNow) {
FldEraseField(pFld);
FldDrawField(pFld);
}
return;
}
// Allow space for null char
uwSize = StrLen(pSrcStr) + 1;
// Get current handle if it exists and reset the field
hString = FldGetTextHandle(pFld);
FldSetTextHandle(pFld, NULL);
if (hString) {
// Resize the existing handle, if it exists
if (MemHandleResize(hString, uwSize))
goto Exit;
} else {
// Must create a new handle
hString = MemHandleNew(uwSize);
if (!hString)
return;
}
// Copy over the new text
pText = MemHandleLock(hString);
StrCopy(pText, pSrcStr);
MemHandleUnlock(hString);
Exit:
// Set the new text handle
FldSetTextHandle(pFld, hString);
// Draw field (only if form is already drawn)
if (fDrawNow) {
FldEraseField(pFld);
FldDrawField(pFld);
}
}
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/