ItemPrevious

 (Available in 00 TS Tools(Base) - TS_Tools_PointerSafe)

Purpose

Get a pointer to the previous item

Syntax

pItemPointer:=oPointerSafe:ItemPrevious( [LOGIC] )

Arguments

lWrap
LOGIC

Description

Get a pointer to the previous item, This method is provided for the application programmer and can be used to navigate ( iterate ) the data items. The properties 'ItemCount' and 'ItemIndex' are used to initalize the number of items and to set the index.

Returns

pRetVal = PTR

Example

METHOD UsingThePointerSafe( ) CLASS MyObject
LOCAL oPointerSafe AS TS_PointerSafe
LOCAL pItem AS PTR
   oPointerSafe:=TS_PointerSafe{ SELF, 10, _SIZEOF( _WinGUID ) }
   oPointerSafe:ItemAdd( TS_GUID_IDispatch( ) )
   oPointerSafe:ItemAdd( TS_GUID_IUnknown( ) )
   oPointerSafe:ItemAdd( TS_GUID_ITypeInfo( ) )
   IF oPointerSafe:ItemLocate( TS_GUID_ITypeInfo( ) )
      oPointerSafe:ItemDel( oPointerSafe:ItemIndex )
   END
   IF !oPointerSafe:ItemLocate( TS_GUID_ITypeInfo( ) )
      oPointerSafe:ItemAdd( oPointerSafe:ItemIndex )
   END
   oPointerSafe:ItemFirst( )
   WHILE pItem<>NULL_PTR
      IF pItem<>NULL_PTR
         SELF:UseItem( pItem )
      END
      pItem:=oPointerSafe:ItemNext( )
   END
   oPointerSafe:ItemLast( )
   WHILE pItem<>NULL_PTR
      IF pItem<>NULL_PTR
         SELF:UseItem( pItem )
      END
      pItem:=oPointerSafe:ItemPrevious( )
   END
   oPointerSafe:ItemFirst( TRUE )
   WHILE oPointerSafe:ItemNext( )<>NULL_PTR
      SELF:UseItem( oPointerSafe:ItemPTR )
   END
   oPointerSafe:ItemLast( TRUE )
   WHILE oPointerSafe:ItemPrevious( )<>NULL_PTR
      SELF:UseItem( oPointerSafe:ItemPTR )
   END
RETURN SELF

Source

METHOD ItemPrevious( lWrap:=FALSE AS LOGIC ) AS PTR PASCAL CLASS TS_PointerSafe
LOCAL pRetVal AS PTR
   TSTrace Enter
   IF SELF:_BytesPointer<>NULL_PTR .AND. SELF:_BytesAllocated ; ...
  ... <>0
      DO CASE
      CASE SELF:_ItemIndex<1
         SELF:_ItemIndex:=1
      CASE SELF:_ItemIndex>SELF:_ItemCount
         SELF:_ItemIndex:=SELF:_ItemCount ; ...
        ... +1
      END
      SELF:_ItemIndex-=1
      IF SELF:_ItemIndex<1
         IF lWrap
            SELF:_ItemIndex:=SELF:_ItemCount
            IF Between( SELF:_ItemIndex, 1, SELF:_ItemCount  ; ...
           ... )
               pRetVal:=SELF:_BytesPointer+( SELF:_ItemSize ; ...
              ... *( SELF:_ItemIndex-1 ) )
            ELSE
               pRetVal:=NULL_PTR
            END
         ELSE
            SELF:_ItemIndex:=1
            pRetVal:=NULL_PTR
         END
      ELSE
         pRetVal:=SELF:_BytesPointer+( SELF:_ItemSize ; ...
        ... *( SELF:_ItemIndex-1 ) )
      END
   ELSE
      TSTrace Warning "!(SELF:_BytesPointer<>NULL_PTR .AND. SELF:_BytesAllocated<>0)"
      pRetVal:=NULL_PTR
   END
   TSTrace Leave
RETURN pRetVal