You are trying to use a pointer resizing function on a chunk that is actually a handle - i'm not sure that will work. Use MemHandleResize instead (which is much more likely to work without an error anyways, as the chunk can be moved if necessary to get a big enough chunk whereas the MemPtrResize cannot move the chunk and instead returns an error if there isn't enough room).
Even better, why not ensure the field has enough memory to hold your maximum length number to start with and dispense with all the resizing - seems like you're doing a lot of (error prone) work just to save a few bytes.... K -----Original Message----- From: Edward P. Ross [mailto:[EMAIL PROTECTED]] Sent: Saturday, September 28, 2002 6:57 PM To: Palm Developer Forum Subject: Changing Field Text I have been hesitating to post this question as I should be able to figure this out - but it's been staying oe step ahead of me. I have two repeating buttons on my form (one that increments a numeric value in a field up, and one that increments the number down). I am using the well known set of functions such as SetFieldTextFromStr that have been propagated on this list a hundred times and in books, etc. But that is not the problem. I have two functions, one below and another that decrements the integer by one. This code is choking on the line "StrIToA(fldTextPos1,tempNum);". I have found messages in the list describing this issue and I have resized the ptr to change with the txt field changes. The error is: "Application just wrote to memory location ... which is in Memory manager data structures." It gets the error when go from say 0, past 10 (double digit number), back down below 10, and then back over 10. Can anyone take a quick look and see if I am missing something? Honestly, it has to be something really dumb. Thanks for any pointers (no pun intended). Ed Ross MemHandle txtH; FieldPtr fldPos1; static Int32 tempNum = 0; Char *fldTextPos1; case frmFormUpPos1Repeating: // Get a pointer to the Pos1 field fldPos1 = (FieldType *) FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, frmStrengthPos1Field)); // Get a handle to the text in the field txtH = FldGetTextHandle(fldPos1); if (txtH) { // Set the handle to NULL FldSetTextHandle(fldPos1, NULL); // Lock the handle and assign the value to a CharPtr fldTextPos1 = MemHandleLock(txtH); // Convert the text to an integer tempNum = StrAToI(fldTextPos1); // inc the integer tempNum++; // Resize pointer to minimum needed if (tempNum > 99) { MemPtrResize(fldTextPos1, 4); } else if (tempNum > 9) { MemPtrResize(fldTextPos1, 3); } else { MemPtrResize(fldTextPos1, 2); } // Convert the new value to a CharPtr and set the text field StrIToA(fldTextPos1,tempNum); <==========================ERROR SetFieldTextFromStr(frmStrengthPos1Field, StrIToA(fldTextPos1, tempNum)); } // Free the handle if it's locked if (txtH != NULL) MemHandleFree(txtH); break; -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ ------------------------------------------ The information in this transmittal and any attachments is privileged and confidential and is intended only for the recipient(s) listed above. You are hereby notified that any unauthorized distribution or copying of this transmittal or its attachments is prohibited. If you have received this transmittal in error, please notify Invivodata immediately at (831) 438-9550. ------------------------------------------ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
