xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HGetAutoAdd()

Retrieves the AutoAdd attribute of a hash.

Syntax

HGetAutoAdd( <hHash> ) --> lIsAutoAdd

Arguments

<hHash>
A variable referencing the hash to retrieve the attribute from.

Return

The function returns the AutoAdd attribute of <hHash> as a logical value.

Description

The function retrieves an attribute of a hash that identifies whether or not automatic creation of key/value pairs is permitted in the context of inline assignments or the HSet() function.

By default, this attribute is .T. (true) when a new hash is created. This causes the assignment of a value to a non-existent key to create a new key/value pair in the hash. This default behaviour can be switched off using function HSetAutoAdd().

Info

See also:Hash(), HGetCaseMatch(), HSet(), HSetAutoAdd(), HSetCaseMatch()
Category: Hash functions , xHarbour extensions
Source:vm\hash.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the automatic creation of key/value
// pairs when a value is assigned to a non-existent key, and how
// to prevent this.

   PROCEDURE Main
      // create an empty hash
      LOCAL hHash := {=>}

      // Populating the hash:
      hHash[ 'first key'  ] := 'first value'
      hHash[ 'second key' ] := 'second value'
      hHash[ 'third key'  ] := 'third value'

      ? Len( hHash )                             // result: 3

      HSetAutoAdd( hHash, .F. )
      hHash[ 'fourth key' ] := 'fourth value'    // runtime error
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe