! *viewer/list.name.value.pvc - Name/Value Pair Object
! By Gord Davey
! (c) Copyright 2003-2005 Sage Software Canada Ltd.
! Version Info:
! Source Code File: $RCSfile: list.name.value.pvs,v $   Version: $Revision: 1.4 $
!      Last Edited: $Date: 2005/10/14 15:31:18 $   Author: $Author: gordd $
!
! This object contains the logic to manipulate an adhoc list of name value pairs
! Number of Name/Value Pairs is limited only by memory and ProvideX Array Limits. (v6 10 million / 2)
!
def class "*viewer/list.name.value"
!
    property Version$ = mid(mid("$Revision: 1.4 $",12), 1, len(mid("$Revision: 1.4 $",12)) - 2)
    local Item$, MaxItems
!
    property Items      set err          ! Count of the number of items to return
!
    ! returns 0 on success, not 0 for error
    function GetItem(Item%, Name$, Value$)  ! Returns the prop and value for a given item
        enter (Item%), Name$, Value$

        Name$ = ""
        Value$ = ""
        if Item% < 1 or Item% > Items \
            then return 41

        Name$ = Item$[Item%, 1]
        Value$ = Item$[Item%, 2]
        return 0
!
    ! returns item number if found, 0 if not
    function GetItem(Name$, Value$)
        enter (Name$), Value$

        Value$ = ""
        result = 0

        if Items < 1 \
            then return 0

        for x = 1 to Items
            if ucs(Item$[x, 1]) = ucs(Name$) then \
            {   Value$ = Item$[x, 2]
                result = x
                break
            }
        next x
        return result
!
    ! returns 0 on success, not 0 for error
    function SetItem(Item%, Name$, Value$)
        enter (Item%), (Name$), (Value$)

        if Item% < 0 or Item% > Items \
            then return 41

        if Items >= MaxItems then \
        {   if MaxItems = 0 \
                then dim Item$[1 : 1, 1 : 2]
            seterr RedimFailedReturnNum
            redim Item$[1 : MaxItems + 10, 1 : 2]
            MaxItems += 10
        }

        if Item% = 0 \
            then Item% = ++Items

        Item$[Item%, 1] = Name$
        Item$[Item%, 2] = Value$
        return 0
!
    ! returns item number if set, 0 if not
    function SetItem(Name$, Value$)
        enter (Name$), (Value$)

        if Items >= MaxItems then \
        {   if MaxItems = 0 \
                then dim Item$[1 : 1, 1 : 2]
            seterr RedimFailedReturnZero
            redim Item$[1 : MaxItems + 10, 1 : 2]
            MaxItems += 10
        }

        Item% = ++Items

        Item$[Item%, 1] = Name$
        Item$[Item%, 2] = Value$
        return Item%

fnend
!
RedimFailedReturnNum:
    return 42
!
RedimFailedReturnZero:
    return 0
