Steve,

You are allocating 8 byte for every string, but using only 2. May be
this is why your code is crashing?

-- 
Best regards,
             Boris




Steve,

Friday, August 8, 2003, 12:42:28 AM, you wrote:

SK> Boris,

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

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

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

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


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

SK>     LstSetListChoices(lstP, lstArray, 2);

SK>     LstDrawList(lstP);

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



SK> "Boris Epshteyn" <[EMAIL PROTECTED]> wrote in message
SK> 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,
SK> 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]
>>
>>
>>




                           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