Boris,

Although I do not have a solution for you, I too am attempting the same type
of list manipulation.

I have taken your code as an example, however am running into problems.

My code is similar to yours, however, I am not reading the info from a DB
instead it is hard coded.  You said that you were loading the list fine,
just having cleanup problems, I'm receiving a fatal error trying to load the
list...  What am I doing wrong?

static void PopulateList()
{
 char** lstArray = (char**) MemHandleNew(2 * sizeof(char*));
 FormType* frmP = FrmGetActiveForm();
 ListType* lstP = (ListType*) FrmGetObjectPtr(frmP, lstDesc);


 lstArray[0] = (char*)MemPtrNew(8);
    StrCopy(lstArray[0], "a");
    lstArray[1] = (char*)MemPtrNew(8);
    StrCopy(lstArray[1], "b");

    LstSetListChoices(lstP, lstArray, 2);

    LstDrawList(lstP);

    for (int i = 0; i < 2; i++) {
  MemPtrFree(lstArray[i]);
 }
 MemPtrFree(lstArray);
}



"Boris Epshteyn" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Hi,
>
> I have an interesting problem. I am allocating an array of strings.
> This array is filled from the database and then used for populating
> pop-up list. When program is ran, list pops up fine, item gets
> selected, but when I tap on the trigger again I get:
> "just read from the ... which is the reserved field of the
> frmControlObj," bla-bla-bla.
>
> If my clean-up portion of the code is commented out, everything runs
> fine, but creates memory leaks. Clean-up portion is:
> for (i = numRec - 1; i >= 0; i--)
> {
> MemPtrFree(programsArray[i]);
> }
> MemPtrFree(programsArray);
>
> I would appreciate any ideas why it is happening. The code is bellow:
>
>
> static Boolean frmNewM_trProg_OnSelect(EventPtr event)
> {
>         ListType *list = GetObjectPtr(lstPrograms);
>         Int16 listItem, cardNo;
>         UInt32 numRec = 0;
>         Err err;
>         char** programsArray;
>         MemHandle record;
>         LocalID progLocID;
>         Program* prog;
>         int i;
>         MemPtr ptr;
>         err = DmOpenDatabaseInfo(progDB, &progLocID, NULL, NULL,&cardNo,
NULL);
>         if (progLocID != 0)
>         {
>            err = DmDatabaseSize(cardNo, progLocID, &numRec, NULL, NULL);
>         }
>         programsArray = (char**)MemPtrNew(numRec * sizeof(char*));
>
>         for (i = 0; i < numRec; i++)
>         {
>            record = DmQueryRecord(progDB, (UInt16)i);
>            if (record)
>            {
>               prog = (Program*)MemHandleLock(record);
>               ptr = &prog->programName;
>               programsArray[i] = (char*)MemPtrNew(StrLen(ptr) + 1 );
>               StrCopy(programsArray[i], ptr);
>               MemHandleUnlock(record);
>            }
>         }
>         LstSetListChoices(list, programsArray, numRec);
>         listItem = LstPopupList(list);
>
>         if(listItem != -1)
>         {
>                 ControlType *trg = GetObjectPtr(trProg);
>                 CtlSetLabel(trg, programsArray[listItem]);
>         }
>         for (i = numRec - 1; i >= 0; i--)
>         {
>                 MemPtrFree(programsArray[i]);
>         }
>         MemPtrFree(programsArray);
>         return true;
> }
>
>
>
>
> --
> Best regards,
>  Boris                          mailto:[EMAIL PROTECTED]
>
>
>



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

Reply via email to