Ah, yes, that's the other little trick related to using a draw function.
There is no data in the char ** parameter of the list structure, so you
can't use lstgetselectiontext. You will still need a string that
persists for as long as your control does and you are responsible for
allocating and freeing it. You would have to do the following based on
the code you posted:
char *ctlLabel; //This is your string for the control label that's
going to have to hang around
MemHandle h = DmQueryRecord(myDB, prefs.lastSelection);
dbEntry = MemHandleLock(h);
ctlLabel = MemPtrNew(StrLen(dbEntry->name);
StrCopy(ctlLabel, dbEntry->name);
ctrlP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, myPop));
CtlSetLabel(ctrlP, ctlLabel);
MemHandleUnlock(h);
Mind you the above has no error handling, etc, but I think you can get
the jist of the fact that you would have to pull the data from your
database again and it has to be in a string that lives as long as the
control is being displayed.
Hope this helps,
DeAnna
-----Original Message-----
From: Andrew Perron [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 21, 2001 3: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
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/