| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Enables or disables associative array compatibility for an empty hash.
HSetAACompatibility( <hHash>, <lToggle> ) --> lSuccess
The function returns a logical value indicating success (.T.) or failure (.F.) of the operation.
The functions accepts an empty hash and toggles associative array compatibility. If this is switched on, values of a hash can be retrieved not only with the hash key, but also using their numeric ordinal position. Hash access can then be programmed using the array element operator and a numeric index.
| See also: | Array(), HaaGetKeyAt(), HaaGetPos(), HaaGetRealPos(), HaaGetValueAt(), HaaSetValueAt(), Hash(), HGetAACompatibility() |
| Category: | Associative arrays , Hash functions , xHarbour extensions |
| Source: | vm\hash.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example outlines the possibilities for accessing values
// of a hash when associative array compatibility is switched on.
PROCEDURE Main
LOCAL hArray := Hash(), aPos, nPos
HSetAACompatibility( hArray, .T. )
HSetCaseMatch( hArray, .F. )
hArray[ "One" ] := 10
hArray[ "Two" ] := 20
hArray[ "Three"] := 30
hArray[ "Four" ] := 40
hArray[ "Five" ] := 50
? hArray[1] // result: 10
? hArray[2] += 100 // result: 120
? hArray:Three // result: 30
? hArray["Four"] + hArray[5] // result: 90
RETURN
http://www.xHarbour.com