I'm "attempting" to populate an empty list object when a form is loaded.
The list is linked to a Pop-up trigger, and the information going into the
dropdown list will be coming from a database.
I searched through some archives here on escribe, but I'm still not sure
exactly how to pull this off. I have a database set up with records for
testing. This is what I've attempted so far. Does anyone know if I'm on
the right track or if I'm way off course?
If someone has a simple example they could send me, I'd really appreaciate
it!
This function is something modified which I seen on this newsgroup, and I've
modified it.
/***********************************************************************
*
* FUNCTION: vnoDrawList()
*
* DESCRIPTION: Draws the dynamic dropdown list
*
* PARAMETERS: - frm
*
* RETURNED: nothing
*
***********************************************************************/
void vnoDrawList(FormPtr frm)
{
tblPackedPvnoPtr p;
tblPvno thePvno;
ListPtr lst;
VoidHand ChoicesHandle;
VoidHand ChoicesPtrsHandle;
VoidHand record;
VoidHand choices;
RectangleType lstRect;
Word itemIndex;
UInt numRecords;
Int lstWidth;
numRecords = DmNumRecords(gPvnoDB);
if(numRecords)
{
itemIndex = FrmGetObjectIndex(frm, NfoGeneralVehicleNumberList);
lst = GetObjectPtr(itemIndex);
// Set custom draw func here
LstSetDrawFunction(lst, vnoListDrawFunc);
// Get the usable width of the list rectangle.
FrmGetObjectBounds (frm, itemIndex, &lstRect);
lstWidth = lstRect.extent.x - 2;
// Allocate an initial block for the list choices.
ChoicesHandle = MemHandleNew(sizeof(char));
// Lock down the block and set it's initial value to an empty
string.
choices = (char *)MemHandleLock(ChoicesHandle);
*choices = 0;
// Build up the choices.
// A sequence of strings packed one after another, one for each
record.
for(itemIndex = 0; itemIndex < numRecords; itemIndex++)
{
// Query Record
record = DmQueryRecord(gPvnoDB, itemIndex);
// Lock the Record and unpack it
p = MemHandleLock(record);
UnpackPvno(&thePvno, p);
// Add the string to choices
// Unlock the record
MemHandleUnlock(record);
}
// Create an array of pointers from the choices strings.
ChoicesPtrsHandle = SysFormPointerArrayToStrings(choices,
numRecords);
// Set the list choices from the array of pointers.
LtSetListChoices(lst, (char **) MemHandleLock(ChoicesPtrsHandle),
numRecords);
}
}
This function is pretty much straight from the Palm Programming book
/***********************************************************************
*
* FUNCTION: vnoListDrawFunc()
*
* DESCRIPTION: Draws the list of Vehicle Numbers
*
* PARAMETERS: - itemNum
* - bounds
* - *data
*
* RETURNED: nothing
*
***********************************************************************/
void vnoListDrawFunc(UInt itemNum, RectanglePtr bounds, CharPtr *data)
{
VoidHand stringsHandle = DmGetResource('tSTL',
NfoGeneralVehicleNumberList);
if(stringsHandle)
{
StrListPtr stringsPtr;
CharPtr s;
stringsPtr = MemHandleLock(stringsHandle);
s = stringsPtr->firstString;
while(itemNum-- > 0)
s += StrLen(s) + 1; // Skip this string, including null byte
WinDrawChars(s, StrLen(s), bounds->topLeft.x, bounds->topLeft.y);
MemHandleUnlock(stringsHandle);
DmReleaseResource(stringsHandle);
}
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/