xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ADel()

Deletes an element from an array.

Syntax

ADel( <aArray>, <nElement>, [<lShrink>] ) --> aArray

Arguments

<aArray>
A variable holding the array to delete an element from.
<nElement>
This is a numeric expression indicating the ordinal position of the array element to delete. It must be in the range between 1 and Len(<aArray>).
<lShrink>
Optionally, a logical value can be specified. If .T. (true) is passed, the length of the array is reduced by one element. The default value is .F. (false) leaving the number of elements in <aArray> unchanged.

Return

The return value is a reference to <aArray>.

Description

The array function ADel() deletes the element at position <nElement> from the array <aArray>. All subsequent elements are shifted up by one position so that the last element contains the value NIL when the function returns. This default behaviour leaves the number of elements in the array unchanged.

If the third parameter <lShrink> is specified as .T. (true), the last element is removed from the array and the number of elements is reduced by 1.

Info

See also:AAdd(), ACopy(), AFill(), AIns(), ASize()
Category: Array functions
Source:vm/arrayshb.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// This example demonstrates two results of deleting an
// array element

   PROCEDURE Main()
      LOCAL aArray := { "A", "B", "C" }

      ADel( aArray, 2 )

      ? Len( aArray )                    // result: 3
      ? aArray[1], aArray[2], aArray[3]  // result: A C NIL

      ADel( aArray, 2, .T. )

      ? Len( aArray )                    // result: 2
      ? aArray[1], aArray[2]             // result: A NIL

   RETURN

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