You need to handle the popSelectEvent and add the text to the trigger
yourself. The problem is that the system thinks that there is data in your
list and, of course, there isn't. Your handler for popSelectEvent needs to
return true to indicate that the OS should not try to do it itself.
//Ray

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Andrew
Perron
Sent: Thursday, June 21, 2001 12:32 PM
To: Palm Developer Forum
Subject: List Draw Function (was Re: Dynamic List Content?)

Yes, certainly much simpler (now that I understand...) and easy to use with
any number of entries in the database, exactly what I was looking for.
But...

I've created my list drawing function and have told the program to use it
and the list is created properly (i.e. when I tap on it is shows up with the
proper contents), however, the label does not get set (either initially or
when a selection is made) and I get an error (it says it's accessing low
memory).


I'm setting the text as follows:

    static void ListDraw(Int16 item, RectangleType* bounds, Char** data)
    {
        MemHandle h = DmQueryRecord(myDB, item);
        dbEntry = MemHandleLock(h);

        WinDrawChars(dbEntry->name, StrLen(dbEntry->name),
bounds->topLeft.x, bounds->topLeft.y);

        MemHandleUnlock(h);
    }


I'm initializing the form in the following:


    listP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, myList));

    LstSetDrawFunction(listP, ListDraw);
    LstSetListChoices(listP, NULL, DmNumRecords(myDB));

    LstSetSelection(listP, prefs.lastSelection);
    LstSetTopItem(listP, prefs.lastSelection);

    ctrlP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, myPop));
    CtlSetLabel(ctrlP, LstGetSelectionText(listP, prefs.lastSelection));

    FrmDrawForm(frmP);


Thanks again for all the help you've been.

Andrew


DeAnna Davidson wrote:

> Andrew,
>
> Using the popup list, you really should just implement your own ListDraw
> function.  I have a number of apps that list data from a database and
> they all just use their own draw function.  It is simpler than trying to
> manage the memory of the char ** for the list data.  At least look at
> the docs on how to implement a list draw function, and if you get stuck,
> ping the list and I'm sure we'll help.  However, if you really feel you
> must use the char **, just make sure you allocate enough memory for each
> string in addition to having enough memory for the pointers to the
> strings.  In particular, in the code you have listed, you're going to
> want to do a StrCopy of the data from the database to the char ** for
> the list, so you'll need to have already allocated the memory for it.
> Following your current implementation, consider doing this:
>
> char **myName;
>
> myName = MemPtrNew(sizeof(UInt32) * 28);  //because you know there are
> going to be 28 items
>
> for (int i = 0; i < 28; i++)
> {
>         h = DmQueryRecord(MyDB, i);
>       myEntry = MemHandleLock(h);
>       myName[i] = MemPtrNew(StrLen(myEntry->name));
>         StrCopy(myName[i], myEntry->name);
>         MemHandleUnlock(h);
> }
>
> Be aware that myName has to be around for as long as the list is and
> that you are responsible for freeing the memory associated with myName,
> both of which are annoying factors for managing the memory associated
> with the list.  I would still strongly encourage you to just go ahead
> with a list draw function.
>
> DeAnna
>
> -----Original Message-----
> From: Andrew Perron [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 21, 2001 10:54 AM
> To: Palm Developer Forum
> Subject: Re: Dynamic List Content?
>
> I'm open to suggestions...  I'm using it for a popup list, is there a
> good way
> to make a "popup table"?
>
> Thanks,
>
> Andrew
>
> Stringer wrote:
>
> > >From: Andrew Perron <[EMAIL PROTECTED]>
> > >Date: Wed, 20 Jun 2001 22:46:33 -0400
> > >Well, here I am with some more list problems/questions.
> > > .....
> > >Here's the scenario, I have a database on the palm that contains some
> > >information like so:
> > >
> > >    typedef struct {
> > >    FlpCompDouble MyFloat1;
> > >    FlpCompDouble MyFloat2;
> > >    Char* name;
> > >    } MyData;
> >
> > >There are currently 28 entries and I have a list that I created
> manually
> > >with each of the name entries.  Currently I get access to MyFloat1
> and
> > >MyFloat2 by using the indexes from the static list contents to
> database
> > >records.  I would prefer to also get the name from the database and
> thus
> > >create the list (that way I only have to update the pdb when data
> > >changes...)
> >
> > My recommendation is the 'list' is the wrong UI object to use.
> > You can do better what you are trying to do by using the 'table' UI
> object.
> > That is certainly what I would do!
> >
> > Roger Stringer
> > Marietta Systems, Inc.
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/


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


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

Reply via email to