xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HSet()

Associates a value with a key in a hash.

Syntax

HSet( <hHash>, <xKey>, <xValue> ) --> NIL

Arguments

<hHash>
A variable referencing the hash that receives the key/value pair.
<xKey>
The key of the key/value pair.
<xValue>
The value of the key/value pair.

Return

The function returns always NIL.

Description

HSet() is the functional equivalent of the hash access operator [ ] in conjunction with the inline assignment operator :=. It provides the same functionality for populating a hash or changing the value of existing key/value pais, but is slightly less efficient.

Info

See also:Hash(), HGet(), HGetKeyAt(), HGetPairAt(), HSetValueAt(), HHasKey()
Category: Hash functions , xHarbour extensions
Source:vm\hash.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates two posibilities of populating a hash
// and changing its values.

   PROCEDURE Main
      LOCAL hHash := {=>}

      hHash[ "A" ] := 10
      HSet( hHash, "B", 20 )

      ? ValToPrg( hHash )
      // result: { "A" => 10, "B" => 20 }

      hHash[ "B" ] := 100
      HSet( hHash, "A", 200 )

      ? ValToPrg( hHash )
      // result: { "A" => 200, "B" => 100 }
   RETURN

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