I have a problem with the following code, I save the info in my DB referenced by gDRecPot and in a metho I display it on a list. I have other dynamic lists and I have no problems no matter the number of records. in this case after 5 records, the app crashes.
Related Info name CHAR[60] lastName CHAR[60] Records = 5
Function
static void FillCtePotencialList(ListType *lst){
MemHandle h; DBRecPotType *c; Char **itemList; char nombre[121]; Int16 cantCtes,i; cantCtes = DmNumRecords(gDRecPot); itemList = (Char **) MemPtrNew(MAXPROM * sizeof(Char *)); gCteListChoices = itemList; gCteListNumItems = cantCtes;
for (i=0; i<cantCtes;i++){ h = DmQueryRecord(gDRecPot,i); c = (DBRecPotType *)MemHandleLock(h); StrCopy(name, c->name ); StrCat(nombre, " "); StrCat(nombre, c->lastName ); TxtGlueTruncateString(nombre,131); MemPtrUnlock(c); itemList[i] = (char *) MemPtrNew(121); StrPrintF(itemList[i],nombre); } LstSetListChoices(lst, itemList, cantCtes); }
any ideas?
Any idea what line it crashes on?
Maybe DmQueryRecord() is returning a null handle?
Maybe use StrNCopy() and StrNCat() to make sure you don't overwrite the buffer?
Your StrPrintF() call sure looks weird. If you're not doing formatting, why not just use StrNCopy()?
Maybe skip the temp buffer and build your list string straight into the itemList[i] array? (tho this probably wouldn't cause a crash)
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
