Hi All,

I have written a small application which is duplicate of SHORTCUTs panel
application.  Here, whenever I add a new item to the shortcuts database, I
am getting it displayed on the original shortcuts application, but in my
application, the MainFormInit() which is responsible for reading the data
and displaying the LIST of items, I am getting a bus error.  Can anyone
please help me on what could be the reason for the bus error.  I have given
the complete source code of MainFormInit() for your reference.

Thanking you all in advance.  Regards,  Yuva.


============================================================================
======
 static void MainFormInit(FormPtr frmP)
{
 Err err,err2;
    UInt16 indx;
 UInt16 len,i=0,ctr=0;
 ListPtr lst;
 Char *check4=NULL;
 Char *textP;
 RectangleType lstRect;

 UInt32 newsize;
 Char *choices;
 Err error;
 UInt16 itemIndex,textLen,str_length,lstWidth;
 UInt16 itemIndex2;
 // Prepare to setup the contents of the list for the main form.
 // Get a pointer to the list object.
 frmP = FrmGetActiveForm();
 lst = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, MainShortCutList));

 for(i=0,indx=11;indx<25;indx++,i++)
 {
     UInt8 *data2;
  UInt16 length;
  namep=(Char *)MemPtrNew(200);
  label=(Char *)MemPtrNew(200);

len=sizeof(UInt32)+sizeof(UInt32)+sizeof(UInt32)+sizeof(UInt32)+sizeof(UInt3
2)+sizeof(UInt32)+sizeof(UInt32);
  err  = GrfGetMacroName(indx,namep);
  if(err == 0){
   err2 = GrfGetMacro(namep,data2,&len); }
  if(err != 0)
  {
   totitems=i;
   break;
  }else
  {
   StrNCopy(label,(Char *)data2, len);
//   items2[i] = (Char *)MemPtrNew(20 * sizeof(char *)+1);
   items2[i] = (Char *)MemPtrNew(200);
   textP=(Char *)label;
   length=StrLen(namep)+5+StrLen(label);
   StrCopy(items2[i],namep);
   StrCat(items2[i]," - ");
   if(StrCaselessCompare(textP,"@DS")==0)
   {
    StrCat(items2[i],"[Date Stamp]");
    StrCat(items2[i],"\0");
   }else if(StrCaselessCompare(textP,"@DTS")==0)


    StrCat(items2[i],"[Date Time Stamp]");
    StrCat(items2[i],"\0");
   }else if(StrCaselessCompare(textP,"@TS")==0)


    StrCat(items2[i],"[Time Stamp]");
    StrCat(items2[i],"\0");
   }else
   {
    StrNCat(items2[i],textP,length);
    StrCat(items2[i],"\0");
   }
  }
 }


 // Allocate an initial block for the list choices.
 ChoicesHandle = MemHandleNew(sizeof(char));
 // Lock down the block and set it's initial value to an empty string.
 choices = MemHandleLock(ChoicesHandle);
 *choices = 0;

 str_length=0;
 newsize=0;
 for (itemIndex = 0; itemIndex < totitems; itemIndex++)
 {
  textLen = StrLen(items2[itemIndex]);
  newsize=100+(textLen + str_length + sizeof('\0'));
  MemHandleUnlock(ChoicesHandle);
  error = MemHandleResize(ChoicesHandle, newsize);
  choices = MemHandleLock(ChoicesHandle);
  // Check for fatal error.
  ErrFatalDisplayIf(error, "Could not grow choices for list.");

  // Copy the text from the record to the choices buffer.
  for (ctr = 0; ctr < textLen; ctr++)
  {
   choices[str_length+ctr]=items2[itemIndex][ctr];
  }
  str_length=str_length+ctr;
  choices[str_length++] = 0;
 }

 if(totitems)
 {
 // Create an array of pointers from the choices strings.
 ChoicesPtrsHandle = SysFormPointerArrayToStrings(choices, totitems);

 // Set the list choices from the array of pointers.
 LstSetListChoices(lst, MemHandleLock(ChoicesPtrsHandle), totitems);
 LstDrawList(lst);
 FrmDrawForm (frmP);
 }
}



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