I was having this NULL handle error. I managed to track the error down to
this function

void RestoreScreenStringValue(int ItemId, Char *StringValue ) 
{
        FieldPtr ItemPtr = (FieldPtr)GetObjectPtr(ItemId);
        Handle stringH;
        CharPtr stringP;
        stringH = MemHandleNew(81);
        stringP = MemHandleLock(stringH);
        
        StrCopy( stringP, StringValue );
        FldSetTextHandle (ItemPtr,stringH);
        FldDrawField(ItemPtr);
        
        MemHandleUnlock( stringH ); 
}

It wass screwing up whenever the StringValue parameter wass not pointing to
anything and therefore it is trying to set a handle which is NULL. Dunno if
this will help you but that is the kind of thing which can cause this error.

-----Original Message-----
From: Herman Badenhorst [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 21, 2001 7:53 AM
To: Palm Developer Forum
Subject: "MemoryMgr.c, Line:4340, NULL handle"


I'm also getting the "MemoryMgr.c, Line:4340, NULL handle" error...and I've
found the place where the error occured...but i really dont see anything
wrong?

can you clever guys please point out the "errors" in the next peace of
code...

I need to find the error since i have to deliver the program on monday...

Many Thanks In Advance!
Herman


//-------------------------------------------------------------------
static Boolean FrmSelectVoucherFormHandleEvent(EventPtr event)
{
  Boolean handled = false;
  int i,j,x,y;
  static FormPtr frm;
  static FormPtr *frmNew;                                               
  static ControlPtr ctl;  
  Boolean vFound = false;
  Boolean blnPrevious = false;
  Boolean blnNext = false;
  _VoucherRecord vVoucherRecord;
  _DynamicVouchers_Value vDynamicVoucherRecord;
  _DynamicVouchers_Value_ID vRecordTypeID;
  static char vVoucher[MAX_VS+MAX_VA+MAX_VSDT+MAX_PIN+1];       //represents
VoucherDB
  static char vVoucherTypeQty[MAX_VA+MAX_QTYL+MAX_QTYS+1]; //represents
VoucherTypeDB
  static char vNewRecord[MAX_VA+MAX_QTYL+MAX_QTYS+1];           //represents
VoucherTypeDB 
  static char vNewRecord1[MAX_VA+MAX_QTYL+MAX_QTYS+1];
  static char vVoucherTypeID[MAX_VA+MAX_SUP_ID+1];              
  static char vNewRecordID[MAX_VA+MAX_SUP_ID+1];                
  static char TempQty[MAX_QTYL];
  static char vVoucherValue[MAX_VA];                     
  int vTotal;                                                   //total tock
on hand integer value
  static int vButtonCount;
  static int VoucherQtyL = 0;                                   //quantities
per voucher (
  static int vcount;
  EventType newEvent;
  char vStrTotalSold[10];                                       //total
stock on hand string value
   
  switch (event->eType) {
    case ctlSelectEvent:  // A control button was pressed and released.
      if (event->data.ctlEnter.controlID == frmSelectVoucherCmdReturnButton)
{
        FrmGotoForm(FrmPilotForm);
        vRecordCount = 0;
        handled = true;
        break;
      }
      else if (event->data.ctlEnter.controlID == 5750) {
//Next
        FrmGotoForm(FrmSelectVoucherForm);
        handled = true;
        break;         
      }     
      else if (event->data.ctlEnter.controlID == 5751) {
//Previous
        FrmGotoForm(FrmSelectVoucherForm);
        vRecordCount = vRecordCount - vButtonCount - 8;
        handled = true;
        break;         
      }     
      else {
        for (i=0;i<DmNumRecords(DynamicTypeIDDB);i++) {         
          ReadRecord(DynamicTypeIDDB,vVoucherTypeID,i);
       
          if (StrLen(vVoucherTypeID) != MAX_VA+MAX_SUP_ID)
            continue;

          StrNCopy(vRecordTypeID.dVoucherValue,vVoucherTypeID,MAX_VA);
//get the supplier               
          vRecordTypeID.dVoucherValue[MAX_VA] = 0;
            
 
StrNCopy(vRecordTypeID.dVoucherID,vVoucherTypeID+MAX_VA,MAX_SUP_ID);
//get the supplier               
          vRecordTypeID.dVoucherID[MAX_SUP_ID] = 0;
                              
          if (event->data.ctlEnter.controlID ==
StrAToI(trim(vRecordTypeID.dVoucherID))) { 
 
StrCopy(gVoucherSelectedtoSellFormOrigin,trim(vRecordTypeID.dVoucherValue));
            FrmGotoForm(FrmFirstSaleConfirmationForm);
            handled = true;
            break;
          }
        }
      }
      break;
 
    case frmOpenEvent:  
      // Determine amount of vouchers left for each type
      vTotal = 0;
      for (j=0;j<DmNumRecords(DynamicTypeDB);j++) {             //read all
the different suppliers from DynamicSupplierDB
        VoucherQtyL = 0;

        ReadRecord(DynamicTypeDB,vVoucherTypeQty,j);
        
        if (StrLen(vVoucherTypeQty) != MAX_VA+MAX_QTYL+MAX_QTYS)
          continue;      
        
 
StrNCopy(vDynamicVoucherRecord.dVoucherValue,vVoucherTypeQty,MAX_VA);
        vDynamicVoucherRecord.dVoucherValue[MAX_VA] = 0;
               
        for (i=0;i<DmNumRecords(VoucherDB);i++) {
          ReadRecord(VoucherDB,vVoucher,i);

          if (StrLen(vVoucher) != MAX_VS+MAX_VA+MAX_VSDT+MAX_PIN+MAX_SLD)
            continue;

          StrNCopy(vVoucherRecord.Voucher_Type,vVoucher,MAX_VS);
          vVoucherRecord.Voucher_Type[MAX_VS] = 0;
          trim(vVoucherRecord.Voucher_Type);

          StrNCopy(vVoucherRecord.Voucher_Amount,vVoucher+MAX_VS,MAX_VA);
          vVoucherRecord.Voucher_Amount[MAX_VA] = 0;

 
StrNCopy(vVoucherRecord.Voucher_Sold,vVoucher+MAX_VS+MAX_VA+MAX_VSDT+MAX_PIN
,MAX_SLD);
          vVoucherRecord.Voucher_Sold[MAX_SLD] = 0;
          trim(vVoucherRecord.Voucher_Sold);
               
          if
(StrCaselessCompare(vVoucherRecord.Voucher_Type,gSupplierFormOrigin) == 0)
            if (StrCaselessCompare(vVoucherRecord.Voucher_Sold,NOT_SOLD) ==
0)
              if
(StrCaselessCompare(vVoucherRecord.Voucher_Amount,vDynamicVoucherRecord.dVou
cherValue) == 0) {
                VoucherQtyL++;
                //handled = true;
              }
        } //for i      

        // update the DynamicTypeDB so that the voucher qty info is added

        StrCopy(vNewRecord,vDynamicVoucherRecord.dVoucherValue);
//Amount/Type
        StrIToA(TempQty,VoucherQtyL);
//convert int to str
        StrPrintF(vNewRecord1,"%s%*d",vNewRecord,MAX_QTYL,VoucherQtyL);
//add qty 4 characters wide to end of vNewRecord              
        StrCat(vNewRecord1,"    ");
//MAX_QTYS
        EditRecord(DynamicTypeDB,vNewRecord1,j);
//update the DynamicTypeDB with Voucher qty
        vTotal = vTotal + VoucherQtyL;
//count all the qty's together
      } //for j

      frm = FrmGetFormPtr (FrmSelectVoucherForm);
//get a pointer to the selectvoucher form
      frmNew = &frm;
//get a pointer to the form pointer

      //clear the DynamicTypeID database
      while (DmNumRecords(DynamicTypeIDDB) > 0) 
        DmRemoveRecord(DynamicTypeIDDB,0);

      //get range to display vouchers "from" and "to"
      //vRecordCount = current record out of the total number of records
      //vcount = how many records depending on vRecordCount to display
      blnPrevious = false;
      blnNext = false;

      if (DmNumRecords(DynamicTypeDB) < 8)
//less than 8 vouchers to display
        vcount = DmNumRecords(DynamicTypeDB);
      else {
        if ((vRecordCount+8) > DmNumRecords(DynamicTypeDB)) {   //display
only calculated qty of voucher buttons
          vcount = (DmNumRecords(DynamicTypeDB) - 8) + vRecordCount;
          blnNext = true;
        }
        else {
//display 8 vouchers buttons
          vcount = vRecordCount+8;
          if (vcount != 8)
//dont diplsy << on first screen
            blnPrevious = true;
          blnNext = true;
        }
      }
      
      if (blnNext) {
        CharPtr vTmp1 = (CharPtr)">>";
        ctl = CtlNewControl (frmNew, 5750, buttonCtl, vTmp1, 24, 140, 18,
15, FntGlueGetDefaultFontID (defaultBoldFont), 8500, false); 
      }
       
      if (blnPrevious) {
        CharPtr vTmp2 = (CharPtr)"<<";
        ctl = CtlNewControl (frmNew, 5751, buttonCtl, vTmp2, 3, 140, 18, 15,
FntGlueGetDefaultFontID (defaultBoldFont), 8501, false); 
      }
      
      vButtonCount = 0;         //number of buttons on the current form
      for (i=vRecordCount;i<vcount;i++) {               //read all the
different suppliers from DynamicSupplierDB       
        ReadRecord(DynamicTypeDB,vVoucherTypeQty,i);

        if (StrLen(vVoucherTypeQty) != MAX_VA+MAX_QTYL+MAX_QTYS)
          continue;
      
 
StrNCopy(vDynamicVoucherRecord.dVoucherValue,vVoucherTypeQty,MAX_VA);
//get the amount
        vDynamicVoucherRecord.dVoucherValue[MAX_VA] = 0;
        StrCopy(vVoucherValue,vDynamicVoucherRecord.dVoucherValue);
        trim(vDynamicVoucherRecord.dVoucherValue);
        
 
StrNCopy(vDynamicVoucherRecord.dVoucherQuantityLeft,vVoucherTypeQty+MAX_VA,M
AX_QTYL);       //get the qty
        vDynamicVoucherRecord.dVoucherQuantityLeft[MAX_QTYL] = 0;
        trim(vDynamicVoucherRecord.dVoucherQuantityLeft);
        
        //add qty next to amount on button eg. V29R (3)
        StrCat(vDynamicVoucherRecord.dVoucherValue," (");
 
StrCat(vDynamicVoucherRecord.dVoucherValue,vDynamicVoucherRecord.dVoucherQua
ntityLeft);          
        StrCat(vDynamicVoucherRecord.dVoucherValue,")");

         //Add the voucher amount/type and id to DynamicTypeIDDB
 
StrPrintF(vNewRecordID,"%s%*d",vVoucherValue,MAX_SUP_ID,5500+vButtonCount);
        AddRecord(DynamicTypeIDDB,vNewRecordID);
        CharPtr vTmp = (CharPtr)vDynamicVoucherRecord.dVoucherValue;
//pointer to amount/qty string
        switch (vButtonCount) {
          case 0:
            x = 6;
            y = 17;
            break;
          case 1:
            x = 84;
            y = 17;
            break;
          case 2:            
            x = 6;
            y = 47;                      
            break;
          case 3:            
            x = 84;
            y = 47;                      
            break;
          case 4:
            x = 6;
            y = 77;
            break;
          case 5:
            x = 84;
            y = 77;
            break;
          case 6:            
            x = 6;
            y = 107;                      
            break;
          case 7:            
            x = 84;
            y = 107;                      
            break;
          default:
            break;  
        }     
        ctl = CtlNewControl (frmNew, (5500+vButtonCount), buttonCtl, vTmp,
x, y, 70, 25, FntGlueGetDefaultFontID (defaultBoldFont), 8000+i, false); 
        vRecordCount++;
        vButtonCount++;
      } //for
      FrmDrawForm (FrmGetActiveForm());

      //display the total stock on hand         
      FieldType *fld =
(FieldPtr)GetObjectPtr(frmSelectVoucherTxtTotalStockOnHandField);
      FldSetTextPtr(fld,StrIToA(vStrTotalSold,vTotal));
      FldRecalculateField(fld,true);
      FldDrawField(fld);
      handled = true;
      break;
    }
  return(handled);
}

-- 
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/

Reply via email to