I hate asking seemingly dumb questions but this one's got me stumped. I'm
populating a list on a form dynamically when the form is opened. I created a
simple test for this by creating an array of strings and using
LstSetListChoices(...) to set the list. This is the code which is called on
frmOpenEvent with the parameter FrmGetActiveForm():

static void
Init(FormPtr frm)
   UInt16    items;
   char     *pStrBlock;
   char     *pStr;
   UInt16    index;
   ListPtr   lstTest;

   // Create the array of string pointers {" 0", " 1", " 2", " 3"}.
   items = 4;
   pStrBlock = MemPtrNew(items * 3);
   for (index = 0, pStr = pStrBlock; index < items; index++, pStr++) {
      pStr += StrPrintF(pStr, "%2u", index);
   }
   hStrArray = SysFormPointerArrayToStrings(pStrBlock, items);
   MemPtrFree(pStrBlock);

   // Initialize the form list box with the array.
   lstTest = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, LstTest));
   LstSetListChoices(lstTest, MemHandleLock(hStrArray), items);

   // Draw the form.
   FrmDrawForm(frm);
}

I have verified that the string array is a list of string pointers and that
all the strings are correct. The LstTest list in the form resource is
initialized with a set of strings {"x4", "x3", "x2", "x1", "x0}. If I do not
perform the Init() procedure then the list shows the initial strings. If I do
perform it I get garbage characters in the list but with the correct number of
items.

According to the frustratingly obtuse docs, I do have to allocate and lock the
array when I give it to the list and keep it allocated and locked until the
list is destroyed. But this does not explain why I only get garbage characters
in my list.

BTW: Do you have to unlock a handle before freeing it or does freeing it take
care of any locks?

Any assistance would be greatly appreciated.

--
The Snake Pit - Development
Curtis Clauson    [EMAIL PROTECTED]
Proprietor




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