ok, this works for me without any problem
it has to be done in 3 stages
1.- statics or globalls variables for the pointers
static Char* p_strChoicesP;
static Char** p_strChoicesPP;
2.- Filling the list dinamically, using the pointers, in the function that
loads the List
UInt16 LoadListWithCatalog(FormPtr frmP, UInt16 ListID, DmOpenRef pDB,
UInt16 uinIniField, UInt16 uinTamField, UInt16 puinIdxPointers) {
//begin:code for filling the strings
.
.
.
.
//end:code for filling the strings
// Create an array of pointers from the choices strings.
ChoicesPtrsHandle = SysFormPointerArrayToStrings(p_strChoicesP,
numRecords);
p_strChoicesPP = MemHandleLock(ChoicesPtrsHandle);
LstSetListChoices(lstP, p_strChoicesPP, numRecords);
return(uinIdxRes);
}
3.- cleaning the memory, in the appropriate FormEventHandler
case frmCloseEvent:
if(strChoicesPP) MemPtrFree(strChoicesPP);
if(strChoicesP) MemPtrFree(strChoicesP);
break;
_____________________________
Andr�s Ram�rez
Ing. de Sistemas
Telf.: (51-1) 99470828
(51-1) 97008654
Previously written
Subject: Re: Error while deallocating memory
From: "Steve K" <[EMAIL PROTECTED]>
Date: Thu, 7 Aug 2003 21:42:28 -0700
X-Message-Number: 43
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/