newStrP has insuficient allocated memory. Instead StrLen try MemPtrSize. But, U still need to reserve more memory.
J�lio F�bio de O. Chagas Gerente de Projetos email: [EMAIL PROTECTED] +55(11)3055-3159 Grupo Quadrata http://www.quadrata.com.br ----- Original Message ----- From: "Todd C. Johnson" <[EMAIL PROTECTED]> Newsgroups: palm-dev-forum To: "Palm Developer Forum" <[EMAIL PROTECTED]> Sent: Tuesday, December 18, 2001 1:13 PM Subject: Trouble with StrCopy and field control > When I execute the following code, I get an error saying: > "ServiceTime just wrote to memory location 0x000026B7, which is in > Memory Manager data structures." > > What am I doing wrong? > > Thanks, > > Todd > > > > **** code starts here *** > DateToDOWDMFormat(gCurrentRecord.start.month, > gCurrentRecord.start.day,gCurrentRecord.start.year, > sysPrefs.longDateFormat,label); > SetFieldTextFromPtr(ServicePeriodStartField, label); > > static FieldPtr SetFieldTextFromPtr(UInt16 fieldID, Char* newstrP) > { > MemHandle txtH; > char *str; > > // get some space in which to stash the string > txtH = MemHandleNew(StrLen(newstrP + 1)); > if (!txtH) > return NULL; > > // copy the string to the locked handle > str =MemHandleLock(txtH); > StrCopy(str, newstrP); > > // Unlock the string handle > MemHandleUnlock(txtH); > > // set the field to the handle > return SetFieldTextFromHandle(fieldID,txtH); > > } > > static FieldPtr SetFieldTextFromHandle(UInt16 fieldID, MemHandle txtH) > { > MemHandle oldTextH; > FormPtr frm = FrmGetActiveForm(); > FieldType *fldP; > > // get the field and the field's current text handle > fldP = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, fieldID)); > ErrNonFatalDisplayIf(!fldP, "missing field"); > > // Retrieve the field's old text handle > oldTextH = FldGetTextHandle(fldP); > > // Set the new text handle for the field > FldSetTextHandle(fldP, txtH); > FldDrawField(fldP); > > // Free the old text handle to prevent memory leak > if (oldTextH) > MemHandleFree(oldTextH); > > return fldP; > } > > > > > -- > For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/ > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
