I am creating a dynamic list in my application, filling the list with
records from a database.

Everything works well except sometimes at the end of the list I see garbage
characters. What am I doing wrong below? Here is the code:

//Global variables
char **ListChoices=0;
Int16 ListNumItems;
//Global variables end

//Local variables
Char **itemList;
 records_record *structPtr;
//Local variables end

     ListNumItems = DmNumRecords(records_StDd); // records_StDd is the DB
name

     if(ListNumItems > 0)
     {
      itemList = (Char **) MemPtrNew(ListNumItems * sizeof(Char *));
            ListChoices = itemList; // save so we can free it later

      for(i = 0; i <= ListNumItems-1; i++)
      {
       structHandle = DmGetRecord(records_StDd, i);
       structPtr = MemHandleLock(structHandle);

       if(structPtr->fld_1 != NULL && structPtr->fld_1 != 0x00)
                                            //structPtr->fld_1 is the field
value from DB
       {
        itemList[i] = (char *) MemPtrNew(100);
        StrNCopy(itemList[i], structPtr->fld_1, 100); // only copy up to 100
bytes
        itemList[i][99] = 0x00; // take care about the 0x00 at the end of
the string
       }

       MemHandleUnlock(structHandle);
       DmReleaseRecord(records_StDd, i, 0);
      }


      if (ListChoices)
      {
             for (i=0; i < ListNumItems; i++)
              MemPtrFree((VoidPtr) ListChoices[i]);

             MemPtrFree((VoidPtr) ListChoices);
             ListChoices=0;
            }

            lstP = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
AddLocationDayList));
            listptr = (ListPtr)FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
AddLocationDayList));
            LstSetListChoices(listptr, itemList, ListNumItems);
            LstDrawList(listptr);



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

Reply via email to