?
Solved

A pointer to an array of strings...

Posted on 2005-04-23
4
Medium Priority
?
1,140 Views
Last Modified: 2013-12-27
I can't get the following code to work...

typedef struct
{
      char szItem[50];
}ShopItem;


static ShopItem Fruit[]=
{
      {"apples"},
      {"pears"},
      {"bananas"},
      {0}
};

int wList = FrmGetObjectIndex(pForm, 1001);
ListPtr pList = (ListPtr) FrmGetObjectPtr(pForm, wList);
      
LstSetListChoices(pList, Fruit, 3);

/*I get a compile error with the parameter "Fruit" on the
   last line of code*/

Any help would be appreciated.

RABMissouri





0
Comment
Question by:rabmissouri
2 Comments
 
LVL 6

Accepted Solution

by:
msjammu earned 100 total points
ID: 13865177
This link conmtains very good information on this...
http://www.palmos.com/dev/support/docs/recipes/lists.html
0
 
LVL 14

Assisted Solution

by:bluelizard
bluelizard earned 100 total points
ID: 13924822
you can't use a regular array to set the list items. what you have to do is take the following steps:

1) pack all the items into one string, i.e., allocate memory and write your choices into it, so that it contains this data:
      apples[0]pears[0]bananas[0]
    ([0] meaning an ASCII-0 character)

2) call the function SysFormPointerArrayToStrings to build an array of pointers.  the paramters are the pointer to the above string and the number of items (3).  the result must be stored in a variable of the type MemHandle.

3) lock the memory chunk you got back from the function above (MemHandleLock(...)) and then call the function LstSetListChoices. paramters are the object pointer to the list (apparently, you already got that one right), the pointer that you got from MemHandeLock (just before), and again the number of items (3).  cast the pointer to the type Char **.

here's a sample (with your code added, i couldn't test it, so some typos might still be in there, but you should get the idea):

  typedef struct
  {
       char szItem[50];
  }ShopItem;
  static ShopItem Fruit[]=
  {
       {"apples"},
       {"pears"},
       {"bananas"},
       {0}
  };

  int wList = FrmGetObjectIndex(pForm, 1001);
  ListPtr pList = (ListPtr) FrmGetObjectPtr(pForm, wList);

  MemHandle st_listptrsmh;
  MemHandle st_listmh;
  Char *mp_temp;
  Char *mp_tempwork;
  Char *mp;
  UInt8 i;  
  st_listmh = MemHandleNew( 30 );
  if ( st_listmh != 0 )
  {
    mp_temp = MemHandleLock( st_listmh );
    mp_tempwork = mp_temp;
    for ( i=0; i<2; i++ )
    {
      StrPrintF( mp_tempwork, "%s", Fruit[i] );
      mp_tempwork = (Char *)( (UInt32)mp_tempwork + (UInt32)( StrLen ( mp_tempwork ) ) + 1 );
      // mp_tempwork now points to the byte after the zero-termination
    }
    MemHandleUnlock( st_listmh );
    st_listptrsmh = SysFormPointerArrayToStrings( mp_temp, 3 );
    if ( st_listptrsmh != NULL )
    {
      mp = MemHandleLock( st_listptrsmh );
      LstSetListChoices( plist, (Char **)mp, 3 );
      MemHandleUnlock ( st_listptrsmh );
    }
  }


--bluelizard
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question