Your structure MyData has a Char* member at the end. That is, it's a pointer
to a string somewhere and not that the bytes starting at that location are
the actual string.  In other words, its not equivalent to having char
name[ x ] where x is the length of the string.

I suspect that your record actually has the string located at that position
instead of a pointer pointing elsewhere. (And if that's not the case you
would need to fix up the pointer.) If your string is a fixed size, use char
name[ x ] where x is the fixed size. If the records are packed (extra
characters aren't in the record) then you would want to use char name[ 1 ]
and realize that the buffer is a StrLen in size.

Your second problem is that you are setting your array of char pointers to
memory that you then unlock. Once you unlock, the pointers you just set may
become invalid and no longer points to what you think they point to.

Personally, I rarely use LstSetListChoices for that reason. It is much
easier to have a draw procedure for the list and just do the drawing of each
individual item. In that case, you can just get the index of the item you
are drawing and then grab that record and draw the string and be done with
it.

Hope this helps.
//Ray


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Andrew
Perron
Sent: Wednesday, June 20, 2001 7:47 PM
To: Palm Developer Forum
Subject: Dynamic List Content?

Well, here I am with some more list problems/questions.

I've gone through and read the 30k messages of this archive paying
special attention to those on lists, but I daresay I am more confused
than before :-(

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

So this is what I'm trying to initialize the list without success.  I'm
obviously having memory aloocating problem (among other things?) but
because I'm confused, I don't know where.

    MyData myEntry;
    ListPtr listP;
    ControlPtr ctrlP;
    MemHandle h;
    Char* myName[28];

    for (int i = 0; i < 28; i++)
    {
        h = DmQueryRecord(MyDB, i);
        myEntry = MemHandleLock(h);
        myName[i] = myEntry->name;
        MemHandleUnlock(h);
    }

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

    LstSetListChoices(listP, myName, 28);

    ctrlP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, myPop));
    LstSetSelection(listP, prefs.mySelection);
    LstSetTopItem(listP, prefs.mySelection);
    CtlSetLabel(ctrlP, LstGetSelectionText(listP, prefs.mySelection));

Is there anything else that you would need to be able to assist me.
Some wise words would do wonders to help clear up my confusion in this
matter, I'm sure there is much that I'm doing backwards, but with your
help I'll learn to do it the right way...

Also, what's the best way to automatically assign the number of elements
to my Char* name[28]?

Thanks,

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/

Reply via email to