Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - listput() add an item to a generic list http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 listput()           Add an item to a generic list
------------------------------------------------------------------------------
 Declaration
   pick.hdr

 Syntax
   func uint listput extern
   param value _LIST pList, ;
         value ulong pData, ;
         value uint  uLength

 Arguments
   pList is a list pointer.
   pData is the address of a data object to store in the list.
   uLength is the length of the list item.

 Return
   The length of the item in bytes.

 Description
   The listput() function stores an arbitrary data object in a generic list.

 Example
   #define EXAMPLE_LIST
   #include example.hdr

   typedef struct CUST
      char( 10 ) cName      // member length is 10 + 1 = 11 bytes
      uint       nAge       // member length is 2 bytes
      logical    lPaid      // member length is 2 bytes
   enddef                   // total length is 15 (#defined below)
   
   proc Test_listput
   vardef
      CUST  sCust           // an instance of the structure
      _LIST pList           // pointer to the list
      uint  n               // counter
   enddef
   pList := pickinit()      // allocate list from dynamic memory
   
   // a list (or array) of structures is generated dynamically
   for n := 1 to 10         // prepare data for ten structures one by one
      sCust.cName := chr( 'A' + n - 1 )     // generate a one-letter "name"
      sCust.nAge  := 30 + n                 // generate a number
      sCust.lPaid := n < 6                  // generate a logical
      listput( pList, &sCust, sizeof( sCust ) ) // add structure to the list
   next
   
   // use the list
   for n := 1 to 10
      listget( pList, &sCust, n )           // retrieve an element
      ? "Item #", padl( istr( n ), 2, ' ' ), ;         // print the data
         sCust.cName, istr( sCust.nAge ), sCust.lPaid
   next
   
   pickclear( pList )                       // get back memory
   endproc

   proc main
   Test_listput()
   endproc

See Also: listget()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson