xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HDel()

Removes a key/value pair from the hash by its key.

Syntax

HDel( <hHash>, <xKey> ) --> NIL

Arguments

<hHash>
A variable referencing the hash to remove a key/value pair from.
<xKey>
<xKey> is the key to delete from the hash.

Return

The function returns always NIL.

Description

The function removes a key/value pair from the hash <hHash>. If the key <xKey> is not found in the hash, a runtime error is raised. Use function HHasKey() to determine the existence of a key.

Note:  deleting a key is the only way to change a key in a hash. If the value must be preserved, use function HGet() to retrieve the value, then remove the key, and finally add the new key with the preserved value.

Info

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

Example

// The function deletes a key/value pair from a hash by key.

   PROCEDURE Main
      LOCAL hHash := Hash( "A",10, "B",20 , "C",30 , "D",40 )

      HDel( hHash, "C" )

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

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