Help me. LstSetListChoices is not working..
I dont know whether my code is wrong or not. What happened is all parameters are correct but Function LstSetListChoices is not working.. It crushes the emulator without error message.. Of course, It will be my mistake in the code.. I will just show u the code anyway.. Please reply this message if u have any sugguestion.. Thank you. __ void FillLetsCookFormListWithData(ListType *titleLst, ListType *categoryLst, ListType *yieldLst) { DBRecipePtr dbRecipePtr; Char**titleItemList; Char**categoryItemList; Char**yieldItemList; int i; const int nItems = GetNumberOfRecipeRecord(); MemHandle h; gListNumItems=numberOfItems; titleItemList = (Char **) MemPtrNew(nItems * sizeof(Char *)); categoryItemList = (Char **) MemPtrNew(nItems * sizeof(Char *)); yieldItemList = (Char **) MemPtrNew(nItems * sizeof(Char *)); if(nItems != 0) { for(i = 0; i nItems; i++) { h = DmGetRecord(gDatabase2, i); if (h) { // could fail due to out of memory! dbRecipePtr = (DBRecipePtr) MemHandleLock(h); //dbRecipePtr = GetRecipeByIndex(i); titleItemList[i] = (char *)MemPtrNew(StrLen(dbRecipePtr-title)); StrCopy(titleItemList[i], dbRecipePtr-title); categoryItemList[i] = (char *)MemPtrNew(StrLen(dbRecipePtr-category)); StrCopy(categoryItemList[i], dbRecipePtr-category); yieldItemList[i] = (char *)MemPtrNew(StrLen(dbRecipePtr-yield)); StrCopy(yieldItemList[i], dbRecipePtr-yield); MemPtrUnlock(dbRecipePtr); DmReleaseRecord(gDatabase2, i, true); } } LstSetListChoices(titleLst, titleItemList, nItems); LstSetListChoices(categoryLst, categoryItemList, nItems); LstSetListChoices(yieldLst, yieldItemList, nItems); } } __ -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Jinyoung Lee wrote: Function LstSetListChoices is not working.. It crushes the emulator without error message.. snip __ void FillLetsCookFormListWithData(ListType *titleLst, ListType *categoryLst, ListType *yieldLst) { What about those input parameters? Do they actually point to valid ListType objects? -- Bob www.rmobile.ca -- Mobile software for handheld computers and smartphones -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Actually, on second thought, I'm thinking that the problem might not be the call to LstSetListChoices at all. The ListType objects may still be invalid, but the bigger mistake would be that you allocated memory for the list elements within your FillLetsCookFormListWithData function(). As soon as you exit that function those memory allocations become invalid, so, when the list tries to draw (not AT the LstSetListChoices command, but probably shortly thereafter) it will crash. Jinyoung Lee wrote: Function LstSetListChoices is not working.. It crushes the emulator without error message.. snip __ void FillLetsCookFormListWithData(ListType *titleLst, ListType *categoryLst, ListType *yieldLst) { What about those input parameters? Do they actually point to valid ListType objects? -- Bob www.rmobile.ca -- Mobile software for handheld computers and smartphones -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
titleItemList[i] = (char *)MemPtrNew(StrLen(dbRecipePtr-title)); StrCopy(titleItemList[i], dbRecipePtr-title); Simple example: - we assume the title is foo - then StrLen(title) is 3, right? - so you allocate a buffer of 3 bytes - then use StrCopy to copy foo into the buffer But what about the trailing NULL-character that is copied with it? It will bust your buffer, since StrCopy writes 4 characters in total. I would write: titleItemList[i] = (char)MemPtrNew(StrLen(dbRecipePtr-title) + 1); This should eliminate the first errors. If it still crashes, mail again. Thomas -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
(somehow my other message appeared without subject and with date set to 1970..) titleItemList[i] = (char)MemPtrNew(StrLen(dbRecipePtr-title)); StrCopy(titleItemList[i], dbRecipePtr-title); Simple example: - we assume the title is foo - then StrLen(title) is 3, right? - so you allocate a buffer of 3 bytes - then use StrCopy to copy foo into the buffer But what about the trailing NULL-character that is copied with it? It will bust your buffer, since StrCopy writes 4 characters in total. I would write: titleItemList[i] = (char)MemPtrNew(StrLen(dbRecipePtr-title) + 1); This should eliminate the first errors. If it still crashes, mail again. Thomas -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
On Thu, 23 Mar 2006, Robert Moynihan wrote: Actually, on second thought, I'm thinking that the problem might not be the call to LstSetListChoices at all. The ListType objects may still be invalid, but the bigger mistake would be that you allocated memory for the list elements within your FillLetsCookFormListWithData function(). As soon as you exit that function those memory allocations become invalid, so, when the list tries to draw (not AT the LstSetListChoices command, but probably shortly thereafter) it will crash. This isn't correct; the memory allocations the OP did were done with MemPtrNew and MemHandleNew. Those don't become invalid on exit from the function where they were done. Dean -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Hi Dean, On Thu, 23 Mar 2006, Robert Moynihan wrote: Actually, on second thought, I'm thinking that the problem might not be the call to LstSetListChoices at all. The ListType objects may still be invalid, but the bigger mistake would be that you allocated memory for the list elements within your FillLetsCookFormListWithData function(). As soon as you exit that function those memory allocations become invalid, so, when the list tries to draw (not AT the LstSetListChoices command, but probably shortly thereafter) it will crash. This isn't correct; the memory allocations the OP did were done with MemPtrNew and MemHandleNew. Those don't become invalid on exit from the function where they were done. Dean But the OP declared them within the context of that function, so those variables (titleItemList, etc.) become invalid for use by the list after the function exits. -- Bob www.rmobile.ca -- Mobile software for handheld computers and smartphones -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Robert Moynihan wrote: Hi Dean, On Thu, 23 Mar 2006, Robert Moynihan wrote: Actually, on second thought, I'm thinking that the problem might not be the call to LstSetListChoices at all. The ListType objects may still be invalid, but the bigger mistake would be that you allocated memory for the list elements within your FillLetsCookFormListWithData function(). As soon as you exit that function those memory allocations become invalid, so, when the list tries to draw (not AT the LstSetListChoices command, but probably shortly thereafter) it will crash. This isn't correct; the memory allocations the OP did were done with MemPtrNew and MemHandleNew. Those don't become invalid on exit from the function where they were done. Dean But the OP declared them within the context of that function, so those variables (titleItemList, etc.) become invalid for use by the list after the function exits. Err I see what you are saying. The memory allocations themselves are not invalid after exiting the function, but the immediate reference to them (the variable declarations) are. So the OP would have to be careful to free that memory using pointers derived from the list itself. -- Bob www.rmobile.ca -- Mobile software for handheld computers and smartphones -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
[Charset ISO-8859-1 unsupported, filtering to ASCII...] Robert Moynihan wrote: Hi Dean, On Thu, 23 Mar 2006, Robert Moynihan wrote: Actually, on second thought, I'm thinking that the problem might not be the call to LstSetListChoices at all. The ListType objects may still be invalid, but the bigger mistake would be that you allocated memory for the list elements within your FillLetsCookFormListWithData function(). As soon as you exit that function those memory allocations become invalid, so, when the list tries to draw (not AT the LstSetListChoices command, but probably shortly thereafter) it will crash. This isn't correct; the memory allocations the OP did were done with MemPtrNew and MemHandleNew. Those don't become invalid on exit from the function where they were done. Dean But the OP declared them within the context of that function, so those variables (titleItemList, etc.) become invalid for use by the list after the function exits. Err I see what you are saying. The memory allocations themselves are not invalid after exiting the function, but the immediate reference to them (the variable declarations) are. So the OP would have to be careful to free that memory using pointers derived from the list itself. True; good point. That is a good reason for using global variables to store pointers to allocated memory, at least if they're pointers one will need to free at some point. (I also suspect that Thomas Damme's message on this topic (to allocate StrLen(...)+1 rather than StrLen(...)) is more where the OP's problem lies.) Dean -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Dean Gahlon wrote: (I also suspect that Thomas Damme's message on this topic (to allocate StrLen(...)+1 rather than StrLen(...)) is more where the OP's problem lies.) I agree 100%. That is fundamental error that, really, couldn't help but crash. I didn't see that problem during my first quick glance at the OP's function. -- Bob www.rmobile.ca -- Mobile software for handheld computers and smartphones -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Thank you very much for replies... But i still cannot make it work... First the input parameters are corroct ( I think ) What i use to get the parameters is following: FormPtr frmP; frmP = FrmGetActiveForm(); (ListType *)(FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID))); And i debugged it by PODS.. I was able to see the pointer although I dont know whether it is correct pointer or not Second, When i debugged the code, there is no problem with Stinrg casting thingy.. I was able to see the contents too.. Do you have any other ideas? It's been a day to solve this problem. anyway thank you very much everybody. -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
Re: Help me. LstSetListChoices is not working..
Sori..finally I got answer.. I had mistake in resource numbering.. I didnt check the other numbering in label.. There were two same resource numbers that are the one for label and the other for list. That's why it crashed.. Anyway thank you,, thany you.. -- For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/