Xbasic

# Array set_dynamic Method

Syntax

V <array>.set_dynamic(Flag as L)

Arguments

FlagLogical

If .t., dynamic sizing will be turned on. If .f., dynamic sizing will be turned off.

Description

Turn on/off the dynamic sizing property of an array.

Discussion

The <array>.set_dynamic() method can be used to turn on/off the dynamic sizing property of an array. The <array>.get_dynamic() method can be used to determine the state of an array's dynamic sizing property.

If you DIM an array with a size of 0 and populate the array using the [] syntax, the dynamic sizing property is automatically turned on. Otherwise, the dynamic sizing property is turned off.

### Example

When you delete entries from an array, the array size does not change. With dynamic array sizing turned on, deleting an entry from an array will resize the array. The following Interactive window session demonstrates:

```dim array[3] as c
array[1] = "alpha"
array[2] = "beta"
array[3] = "gamma"
?array.size()
=3
array.delete(2,1)
?array.dump()
= alpha
gamma
?array.size()
=3```

Now, repeating this exercise, but turning on the array's dynamic sizing property:

```dim array[3] as c
array.set_dynamic(.t.)
array[1] = "alpha"
array[2] = "beta"
array[3] = "gamma"
?array.size()
=3
array.delete(2,1)
?array.dump()
= alpha
gamma
?array.size()
=2```

As mentioned above, if you DIM an array with a size of 0 and then populate the array using the [] syntax, the dynamic sizing property is automatically assumed to be set to .t.. For example:

```dim array[0] as c
array[] = "alpha"
array[] = "beta"
?array.size()
=2
array.delete(2,1)
?array.size()
=1```