I myself have been having a similar problem to that of Andrew Perron..
I need to create a ComboBox (popup-trigger + list control) at runtime.
However, I have chosen the other possibility (the one you all describe as
the hardest).
My problem:
I allocate enough space through MemPtrNew(sizeof(char) * 50), and then fill
that pointer with the different strings I want my listbox filled with
followed by a '\0' character. I do this to then use the
SysFormPointerArrayToStrings() function. What this function does, is return
an array of strings (exactly what I need to pass to LstSetListChoices) when
given a Char* that has all the strings each separataed by a '\0'.
Anyway, so far so good. In fact, the Char** works great! The problem is.. I
cannot MemPtrFree() the Char* I used initially to pass on to
SysFormPointerArrayToStrings(), which is sizeof(char) * 50 -Pretty big-.
Why is this? How should I release the memory? Thanks a lot,
Nicolas Zeitlin
PS: I know you all think I should have chosen the LstDrawFunc() option...
But is there a way to sort this out without having to change my entire code?
Thanks again.
-----Original Message-----
From: DeAnna Davidson <[EMAIL PROTECTED]>
To: Palm Developer Forum <[EMAIL PROTECTED]>
Date: Thursday, June 21, 2001 5:15 PM
Subject: RE: List Draw Function (was Re: Dynamic List Content?)
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/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/