The first problem I'm trying to resolve is when I try and remove a
Dynamically created field control, I'm creating the control with the
following code:

  case ctField: // create a text field
       TestControls[i].iControlID = giNextControlID;
       giNextControlID++;

       nfrmP = FrmGetActiveForm();

   NewField=FldNewField ((void **)&nfrmP,     // form
         TestControls[i].iControlID, // id
         TestControls[i].x,       // x
         y,       // y
         50,       // width
         12,       // height
         stdFont,      // font
           50,       // maxchars
           true,       // editable
           true,       // underlined
           true,       // singleline
           false,       // dynamicsize
           leftAlign,     // justification
           true,       // autoshift
           false,       // hasscrollbar
           false);      // numeric
       // set the value of the field
       SetTextPtr(NewField, TestControls[i].Value, false);
   break;

------ SetTextPtr code
 Boolean SetTextPtr(FieldPtr field, char *s, Boolean redraw)

 {
 MemHandle h = FldGetTextHandle(field);
 char* p;

 if (h)
   {
   FldSetTextHandle(field, NULL);
   if (MemHandleResize(h, StrLen(s) + 1))
     return false;
   }
   else
   {
   h = MemHandleNew(StrLen(s) + 1);
   if (!h)
     return false;
   }

 p = (char *)MemHandleLock(h);
 StrCopy(p,s);
 MemHandleUnlock(h);
 FldSetTextHandle(field,h);
 if (redraw)
   FldDrawField(field);
 return true;
 }

And then removing it with this code:

    frmP = FrmGetActiveForm();
      obj2NDX=FrmGetObjectIndex(frmP,TestControls[ndx].iControlID);
      if (obj2NDX != frmInvalidObjectId)
       {
       FieldPtr field;
       field = (FieldPtr)GetObjectPtr(TestControls[ndx].iControlID);

       MemHandle h = FldGetTextHandle(field);

    if (h)
     {
     SetTextPtr(field, "", false);
        }
              error=FrmRemoveObject (&frmP,obj2NDX);
       }

When running this in the emulator (4.0 Debug rom) it reports a memory leak.
Any ideas of what I'm doing wrong?


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to