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/

Reply via email to