Hmm...hope this helps (although I'm sure SOMEONE will have a better idea):

void MakeArrayList (Char * ListArrayP, UInt16 ItemCount, MemHandle * StringArrayH)
{
        Char **StringArrayP;
        UInt16 i, offset;

        *StringArrayH = MemHandleNew (ItemCount * sizeof (Char *));
        StringArrayP = MemHandleLock (*StringArrayH);
        offset = 0;
        for (i = 0; i < ItemCount; i++)
        {
                StringArrayP[i] = &ListArrayP[offset];
                while (ListArrayP[offset] != 0)
                        offset++;
                offset++;
        }
        MemHandleUnlock (*StringArrayH);
}

void GetStringList (MemHandle *ArrayH, UInt16 * ItemCount, UInt16 category)
{
        RecordType Record;
        MemHandle DmRecordH;
        UInt16 TransIndex;
        UInt16 Offset; 

        Char *ArrayP;
        Char *TheString;
        UInt16 totalSize;
        UInt16 copysize;

        totalSize=50;

        *ArrayH = MemHandleNew(totalSize); // 50 is arbitrary, just make some space, 
we'll shrink later
        ArrayP = MemHandleLock(*ArrayH);
 
        *ItemCount=0; 
        Index = 0;
        DmRecordH = DmQueryNextInCategory (DB, &Index, category);

        while (DmRecordH != NULL)
        { 
                GetRecord (DmRecordH, &Record);
                switch (category)
                {
                case cat1: 
                        TheString = Record.Field1;
                        break;
                case cat2: 
                        TheString = Record.Field2;
                        break;
                case cat3:
                        TheString = Record.Field3;
                }

                copysize = StrLen (TheString) + 1;
                if (Offset + copysize > totalSize)
                {
                        totalSize = Offset + copysize + 50; // 50 is arbitrary here.  
Just keeps from resizing the block EVERY time.
                        MemHandleUnlock (*ArrayH);
                        MemHandleResize (*ArrayH, totalSize);
                        TransArrayP = MemHandleLock (*ArrayH);
                }
                StrCopy (&ArrayP[Offset], TheString);
                Offset += copysize;

                (*ItemCount)++; 
                Index++;
                DmRecordH = DmQueryNextInCategory (DB, &Index, category);
        }

        MemHandleUnlock (*ArrayH);
        MemHandleResize (*ArrayH,Offset);  // Shrink the block back down...just to be 
nice
 }


SOME FORM FUNCTION:
 
        switch (event->eType)
        {
        case frmOpenEvent: 
                // Get the list.  Make an array of pointers and put it in StringArrayH
                GetStringList (&ListArrayH, &ItemCount, category);
                ListArrayP = MemHandleLock (ArrayH); 
                MakeArrayList (ListArrayP, ItemCount, &StringArrayH);
                StringArrayP = MemHandleLock (StringArrayH);

                FontID = FntGetFont ();

                showCount = (ItemCount > 10) ? 10 : ItemCount;
                listHeight = showCount * FntCharHeight ();
                topPosition = 24;

                LstNewList ((void *) &form, tempObject, 40,
                            topPosition, 75, listHeight, FontID, showCount, 
popListPick);
                LocationList = InvGetFrmObjectPtr (form, tempObject);  // tempObject 
is 9999 in my header file.
                LstSetListChoices (TheList, StringArrayP, ItemCount);

                // This routine I wrote "FindListItem" returns the item index in the 
list of the one I want to highlight
                // from a global variable
                ItemCount = FindListItem (TheList, MyPreferences.CurrentListItem);
                PopUp = InvGetFrmObjectPtr (form, popListPick);
                LstSetSelection (TheList, ItemCount);

                // Set the text of the list control 
                CtlSetLabel (PopUp, MyPreferences.CurrentListItem);

                FrmDrawForm (form);
                handled = 1;
                break;



Steve Mann wrote:

>> Could anyone tell me where I could find an example of how to create 
>> this list at runtime, or provide me with some hints.
>
>
> You can use a list drawback function, sidestepping the whole issue of 
> constructing the list. All you need to do is initialize it: # items, 
> selection, etc.
>
> Regards,
> Steve Mann
>



-- 
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