Microsoft Foundation Classes (mfc.hlp) (Table of Contents; Topic list)
CObList::SetAt
CObList                                     Up Contents Index Back
──Microsoft Foundation Classes──────────────────────────────────────────────
 
  void SetAt( POSITION pos, CObject* newElement );
 
  Parameter    Description
 
  <pos>        The POSITION of the element to be set.
 
  <newElement> The CObject pointer to be written to the list.
 
  Remarks
 
  A variable of type POSITION is a kind of "key" for the list. It is not
  the same as an index, and you cannot operate on a POSITION value
  yourself. SetAt writes the CObject pointer to the specified position in
  the list.
 
  You must ensure that your POSITION value represents a valid position in
  the list. If it is invalid, then the Debug version of the library
  asserts.
 
  Example
 
     CObList list;
     CObject* pa;
     POSITION pos;
 
     list.AddHead( new CAge( 21 ) );
     list.AddHead( new CAge( 40 ) ); // List now contains (40, 21)
     if( ( pos = list.GetTailPosition()) != NULL )
     {
         pa = list.GetAt( pos ); // Save the old pointer for deletion
         list.SetAt( pos, new CAge( 65 ) );  // Replace the tail element
         delete pa;  // Deletion avoids memory leak
     }
  #ifdef _DEBUG
     afxDump.SetDepth( 1 );
     afxDump << "SetAt example: " << &list << "\n";
  #endif
 
  The results from this program are as follows:
 
  SetAt example: A CObList with 2 elements
      a CAge at $4D98 40
      a CAge at $4DB8 65
 
  See Also
 
  CObList::Find, CObList::GetAt, CObList::GetNext,
  CObList::GetPrev
 
 
                                     -♦-