| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Retrieves the AutoAdd attribute of a hash.
HGetAutoAdd( <hHash> ) --> lIsAutoAdd
The function returns the AutoAdd attribute of <hHash> as a logical value.
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().
| See also: | Hash(), HGetCaseMatch(), HSet(), HSetAutoAdd(), HSetCaseMatch() |
| Category: | Hash functions , xHarbour extensions |
| Source: | vm\hash.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com