On Mon, 4 Aug 2003 09:59:53 +1000, "Alan Ingleby" <[EMAIL PROTECTED]> wrote:
>
>Ken's right.  Specifically, you *can't* use LstGetSelectionText with a
>dynamic list, so don't.  

What? Why would that be? That's just wrong. 

This is only the case when a (suspicious) program never calls LstSetListChoices.
I think there is foul play here. 

If all that is involved here is a dynamic list, a DrawList callback 
is the wrong way to do it. You would only resort to this if your list
had to display little icons or something. Even if you are doing it the 
wrong way, LstSetListChoices should still be called unless the list 
items don't have any text.

To set dynamic list text, create the list when the need arises and
call LstSetListChoices(). Keep your program simple and let the
OS do the work.

>Use your own code to determine the value.  This shouldn't be hard, as it's 
>effectively the same code you're using in your DrawList function.

I don't have any DrawList functions and I have dozens of Dynamic lists. 
Drawlist methods are not related to dynamic lists. Drawlist callbacks are 
for list choices that don't contain text or can't be displayed as a text 
string. Even then, if they contain text, LstSetListChoices should be called 
in most cases. It is the obvious place to store the text component of the
custom drawn list and simplifies the job of the DrawList callback.

A program could have many 'dynamic lists' that are set into the list
depending on events at another control. LstGetSelectionText() is
free of charge, provides correct results with respect to the last
set of elements given and eliminates the need to remember or organize
this programmatically.

The supplied code is riddled with unchecked possibilities for failure.
*****************************************************************
Char *listText;

ListType *list = GetObjectPtr(ListOrderList);

//What is GetObjectPtr?
//how do you know it succeeded?
//Why isn't there a cast to ListPtr?
//ListOrderList doesn't sound like a resourceID
//Is it a Popup list? Did you note the warning about
//FrmGetActiveForm() in the comments in FrmGetActiveForm()?

listText = MemPtrNew(50);

//what a giant memory leak. There is no attempt to deallocate.
//why are you allocating dynamically?
//How do you know the allocation succeeded?
// Char listText[50] will work just as well
//if dynamic allocation is mandatory, then why not allocate what's needed
//e.g.
// { 
//   if(listText != NULL){      //assuming listText is a global...
//     MemPtrFree(listText);    // take care of this memory leak
//     listText=NULL; 
//   }
//   int n=LstGetSelection(list);
//   if( n!=noListSelection ){
//     CharPtr cp=LstGetSelectionText(list,n);
//     ErrFatalDisplayIf(cp==NULL,"GetSelectionText failed");
//     listText=(CharPtr)MemPtrNew(StrLen(cp)+1);
//     ErrFatalDisplayIf(listText==NULL,"Could'nt allocate listText");
//     StrCopy(listText,cp);
//   }
// }

StrCopy(listText, LstGetSelectionText(list,LstGetSelection(list)));
// what if nothing is selected?

*****************************************************************

regards

bullshark

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to