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 - listreplace() replace a generic list item http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 listreplace()       Replace a generic list item
------------------------------------------------------------------------------
 Declaration
   pick.hdr

 Syntax
   func uint listreplace extern
   param value _LIST pList, ;
         value uint  uItem, ;
         value ulong pData

 Arguments
   pList is a list pointer.
   uItem is the number of the list item to replace.
   pData is the address of a data object to store in the list.

 Return
   The length of the retrieved item in bytes.

 Description
   The listreplace() function replaces an item in a generic list.
   The size of the new item must match the original one. Use the
   listitemlen() function to obtain the size of a list item.

 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_listreplace
   vardef
      CUST     sCust        // an instance of the structure
      _LIST    pList        // pointer to the list
      uint     n            // counter
      char     cString
   enddef
   pList := pickinit()      // allocate list from dynamic memory
   
   // put two structures in the list
   for n := 1 to 2
      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
   
   // display the two structures kept in the list
   for n := 1 to 2
      listget( pList, &sCust, n )           // retrieve an element
      ? "Item #", istr( n ), ;              // print the data
         sCust.cName, istr( sCust.nAge ), sCust.lPaid
   next
   
   // Replace first structure in list with a string. The size of the string
   // must be equal to the length of the data to be replaced.
   cString := "12345678901234"
   listreplace( pList, 1, &cString )
   
   // display second member of list (first one is already replaced)
   ?
   for n := 2 to 2
      listget( pList, &sCust, n )           // retrieve an element
      ? "Item #", istr( n ), ;              // print the data
         sCust.cName, istr( sCust.nAge ), sCust.lPaid
   next
   
   // retrieve first list element, which has been made to be a string
   cString := ""                            // re-initialize string buffer
   listget( pList, &cString, 1 )            // retrieve first list element
   ?
   ? cString                                // display string
   
   pickclear( pList )                       // get back memory
   endproc

   proc main
   Test_listreplace()
   endproc

See Also: listput()

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