Hi fellas

I have this problem with filling a list box!!!
Can someone help me out????

i have a delimited string
eg Water~Milk~Coke~Pizza##

and i want to store this in an array of strings
i.e ReadArray[0]=Water
     ReadArray{1]=Milk etc.
ReadArray is of type Char**
i need this coz i have to fill the listbox dynamically and a list box needs
a pointer to an array of strings. water,milk etc will be the items in the
listbox

i have written this code.....
it seems to work but it gives very erratic memory errors....eg. u r trying
to access memory which is not locked...if i press continue..it works with
some junk characters...
**************************************************************
char **ReadPtr1
MemPtr ReadPtr
Char* DataPtr

ReadHandle = MemHandleNew(1000);
     if (ReadHandle == 0)
      FrmCustomAlert(DataSentAlert,"COULD NOT GET A HANDLE",NULL,NULL);
     else{
      ReadPtr = MemHandleLock(ReadHandle);
      ReadPtr = (UInt8 *) (ReadPtr);

        retval =
NetLibReceive(AppNetRefnum,MasterSocket,ReadPtr,1000,0,0,0,AppNetTimeout,&er
r)

        if (retval > 0){
         DataPtr = (char *)ReadPtr;
         ReadPtr1 = (Char **)MemPtrNew(retval)

      totcnt=0;
    while (StrNCompare(DataPtr,"##",2)!=0){

     cnt=(StrStr(DataPtr,"~") - DataPtr);
     if (cnt>0){
              ReadPtr1[totcnt]=(Char *)MemPtrNew(cnt+2);
              StrNCopy(ReadPtr1[totcnt],DataPtr,cnt);
             DataPtr = DataPtr+cnt+1;
             totcnt++;
     }
           else{
            FrmCustomAlert(DataSentAlert,"Could not get the
count!!",NULL,NULL);
            goto Finish;
           }
    }

          LstRead = GetObjectPtr(MainDynamicList);
        LstSetListChoices(LstRead,ReadPtr1,totcnt);
        LstDrawList(LstRead);
    }

*******************************************************
i have excluded the validations for pointer and return values so that code
looks simple...ne wayz they dont give any errors
It throws error when the LstDrawList function is called. Depending on how
much memory i allocate to ReadPtr1, memory error arise at different items in
the list.It says u r trying to access memory which is not allocated and on
pressing "continue" number of times, the list does get populated but again
if u try to select an item, it throws the same error...


there is some memory allocation problem particularly for ReadPtr1. When i
allocate different amount of memory the errors i get is different.

looking forward to ur suggestions
cheers,
Nihar


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

Reply via email to