Here is the code:
// global variables
char **ListChoices=0;
Int16 ListNumItems;
// global variables end
static Boolean EditFormHandleEvent(EventPtr eventP)
{
Char **itemList;
unsigned int i;
records_record *structPtr; // pointer to record structure
ListType *lstP;
ListPtr listptr;
Int16 theSelection;
Char *theText;
case . . .
.
.
.
case fldEnterEvent: //when you tap on the field the list opens up
if( eventP->data.fldEnter.fieldID == EditFldvalue1Field)
{
FrmSetFocus(frm, FrmGetObjectIndex(frm, EditFldvalue1Field));// field
associated with list
ListNumItems = DmNumRecords(records_DB);// records_DB is the database
from which the records are retrieved to fill the list
itemList = (Char **) MemPtrNew(ListNumItems * sizeof(Char *));
ListChoices = itemList; // save so we can free it later
for(i = 0; i < ListNumItems; i++)
{
structHandle = DmGetRecord(records_DB, i);
structPtr = MemHandleLock(structHandle);
itemList[i] = (char *) MemPtrNew(25); // 25 is maximum size of
structPtr->fld_1
itemList[i] = structPtr->fld_1; // I think I am doing something
terribly wrong here
MemHandleUnlock(structHandle);
DmReleaseRecord(records_DB, i, 0);
}
lstP = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
EditLocList));
listptr = (ListPtr)FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
EditLocList));
LstSetListChoices(listptr, itemList, ListNumItems);
LstDrawList(listptr);
if (ListChoices)
{
for (i=0; i < ListNumItems; i++)
MemPtrFree((VoidPtr) ListChoices[i]);
MemPtrFree((VoidPtr) ListChoices);
ListChoices=0;
}
}
handled = true;
break;
case lstSelectEvent:
if (eventP->data.lstSelect.listID == EditLocList)
{
theSelection = eventP->data.lstSelect.selection;
theText = LstGetSelectionText(eventP->data.lstSelect.pList,
theSelection);
listptr = (ListPtr)FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
EditLocList));
LstEraseList(listptr);
SetFieldText(EditFldvalue1Field, theText, 32, true);
}
handled = true;
break;
.
.
}
"Henk Jonas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> HI,
>
> I think it looks fine, but I guess your allocation of the string-ptrs is
> the problem? Show us the part when you prepare the list for diplaying.
>
> Regards
> Henk
>
> Developer wrote:
>
> > I have been able to create working lists in my application but I am
having
> > trouble with creating dynamic lists that are filled up with records from
a
> > database at runtime.
> > I have tried to follow this example " Lists With Dynamic Content "
> > http://www.palmos.com/dev/support/docs/recipes/lists.html
> > but keep getting this error message "MemoryMgr.c, Line: 4359, Free
handle".
> > I have been struggling with this for 2 days but without any success.
There
> > is something wrong with freeing the memory in this code in the link
above:
> > case frmCloseEvent:
> > if (gYearListChoices) {
> > UInt16 i;
> > for (i=0; i<gYearListNumItems; i++)
> > MemPtrFree((MemPtr) gYearListChoices[i]);
> > MemPtrFree((MemPtr) gYearListChoices);
> > gYearListChoices=0;
> > }
> > break; //remember to leave handled as false
> > I dont see what is the problem. I can post my code here if required. It
has
> > been slightly modifiedas it is retrieving the elements for the list from
the
> > DB.Any pointers to any other examples which do the exact same thing that
I
> > am trying to do will be helpful. I could not find any on other
newsgroup. In
> > short I want to fill a list with records from a database at runtime and
> > display it.Many thanks.
>
>
> --
> -------------------------------------------------------------------------
> Henk Jonas
> Palm OS � certified developer
>
> [EMAIL PROTECTED] www.metaviewsoft.de
> -------------------------------------------------------------------------
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/