xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HSetAACompatibility()

Enables or disables associative array compatibility for an empty hash.

Syntax

HSetAACompatibility( <hHash>, <lToggle> ) --> lSuccess

Arguments

<hHash>
This is a variable referencing an empty hash. If the hash is not empty, a runtime error is raised.
<lToggle>
A logical value must be passed as second parameter. .T. (true) enables associative array compatibility, and .F. (false) disables it.

Return

The function returns a logical value indicating success (.T.) or failure (.F.) of the operation.

Description

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.

Info

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

Example

// 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

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