CC> I have a modal form to display, and I want to load a text field with a
CC> preset value when the form loads. I've found documentation that
CC> describes how to do this, but when I try it, at runtime in the POSE I
CC> get "Invalid field length". The field I'm trying to set is editable,
CC> single-line, and not dynamic size. Its max length is 15.
CC> Could someone tell me what I'm doing wrong? Here is the code, it's in
CC> the AppHandleEvent routine. The error appears not when the meat of the
CC> following code runs, but when the form is displayed (FrmDoDialog()).
CC> -----------------------------------------------------------
CC> FormType* pForm;
CC> UInt16 whichbutton;
CC> MemHandle textH;
CC> FieldType *fieldP;
CC> char *textP;
CC> // global search1 contains initial string
CC> pForm = FrmInitForm(NewSearchForm);
CC> fieldP = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm,
CC> Search1Field));
CC> textH = MemHandleNew(100); // changing this size doesn't help
CC> textP = (char *)MemHandleLock(textH)
CC> if (textP)
CC> {
CC> StrCopy(textP, search1);
CC> MemHandleResize(textH, StrLen(textP)+1);
CC> MemHandleUnlock(textH);
CC> FldSetTextHandle(fieldP, textH);
CC> }
CC> MemHandleFree(textH);
CC> whichbutton = FrmDoDialog(pForm);
CC> etc.
CC> ---------------------------------------------------------------
1. do "MemHandleResize" before "MemHandleLock"
2. delete "MemHandleFree(textH") string from your code. you must delete
MemHandle associated with field when your field will destroy.
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/