void setFieldTextFromString (Word fieldID, CharPtr s) { MemHandle oldH, newH; FormPtr frm = FrmGetActiveForm(); FieldPtr f; CharPtr textP;
newH = MemHandleNew (1 + StrLen (s));
if (newH == NULL) { return; }
textP = (CharPtr) MemHandleLock (newH);
StrCopy (textP, s);
MemHandleUnlock (newH);
f = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, fieldID));
oldH = FldGetTextHandle (f);
FldSetTextHandle (newH);
if (oldH != NULL) { MemHandleFree (oldH); }
FldDrawField (f); }
Not sure if that will fix the problem, but it's an idea.
- Logan
Thank you for the reply. That is actually what my original code looked like, since I copied it from an example. It also caused the same problem.
DTL
Hi
Some time ago I had the exact same problem. Working with memhandles is
a bit trickie, it seems that the problem that exists in Davids code example is
that he has to free newH.
My Problem occured with tables, but my sollution might work with only fields too. My code is similar:
Err BesamungLoadDescription (void * table, Int16 row, Int16 column,Boolean editable, MemHandle * UNUSED_PARAM(dataH), Int16 * dataOffset, Int16 * dataSize, FieldPtr fld)
{ Char *fieldP;
UInt16 fieldSize=TIER_ID*sizeof(Char); UInt16 CopySize=0;
FldSetMaxChars(fld,12);
//if needed create a new handle(possibly not needed) lock it to fieldP
if(EberH[row]==NULL)
{
EberH[row] = MemHandleNew(fieldSize);
fieldP = MemHandleLock(EberH[row]); //reset fieldP write the data to fieldP unlock the handle and set the handle to the current field
MemSet(fieldP,fieldSize,0);
}
else
fieldP = MemHandleLock(EberH[row]);
/*define the maximum length that can be copied into the fields*/
if(StrLen(Besamung_form.Eber[row])>(8)*sizeof(Char))
CopySize=(8)*sizeof(Char);
else
CopySize=StrLen(Besamung_form.Eber[row]); MemMove(fieldP, Besamung_form.Eber[row],CopySize); //in den Speicher des Feldes den Inhalt der Struktur laden MemHandleUnlock(EberH[row]);
FldSetTextHandle(fld, EberH[row]); .
.
. /*minimize the maximum of chars that can be entered by the user*/
FldSetMaxChars(fld,8);
return 0;
}
EberH is a global defined memory handle array. When the form is exited I free the handle
if(EberH[row]!=NULL) MemHandleFree(EberH[row]); EberH[row]=NULL;
and in case I've not every occurance I use
if(EberH[row]!=NULL) MemHandleFree(EberH[row]);
in the stopapplication routine.
hope this helps
Christian Lindemeier
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
