I'm trying to get to use LstSetListChoices() - in conjunction with
SysFormPointerArryToStrings() - to create a bunch of list items
and am having trouble with allocating dynamic pointers. My 'for loop' code
works fine the first time through but always crashes on subsequent
iterations - sometimes the second time through, sometimes the third, etc.
It gives an error saying "...mem chunk locked..." when the error is on the
MemPtrResize line.
Would I want to use a MemHandle instead of a MemPtr? What's the difference?
The problem is in the MemPtrUnlock and MemPtrResize calls.
<<<CODE>>>
pStrings = MemPtrNew(1); // Just get a pointer and put a dummy size in it
for (stringCnt = topRecordInList; stringCnt < topRecordInList +
MAX_HIST_VIEWABLE_ITEMS; stringCnt++) {
if ((hRecord = DmQueryRecord(gDB, stringCnt)) == NULL)
break; // No more records to display
// Lock down that patient's record so we can read from it without the Data
Manager moving it around on us
pPatient = MemHandleLock(hRecord);
// Get a pointer to where the string currently resides in memory
pTempString = &pPatient->firstField + pPatient->offsetLastName;
stringLength = StrLen(pTempString) + 1;
// Resize to accomodate our new string being added to the end
error = MemPtrUnlock(pStrings);
if ((error = MemPtrResize(pStrings, offset + stringLength))) {
ErrAlert(error);
MemHandleFree(hRecord);
MemPtrFree(pStrings);
return;
}
// Add it to the end of our current string
StrCopy(pStrings + offset, pTempString);
// *(pStrings + stringLength - 1) = '\0';
MemHandleUnlock(hRecord);
offset += stringLength;
}
<<<END>>>
--
Jimi Malcolm
Web Content Manager
inburst Internet Media
inburst.com
jimi.malcolm@inburst
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/