Click or drag to resize

ArrayProtect Function (Array)

X#
Protect an array from change in all functions except the one in which it was declared.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION ArrayProtect(
	aTarget AS ARRAY
) AS LOGIC
Request Example View Source

Parameters

aTarget
Type: Array
The array to protect.

Return Value

Type: Logic
TRUE if the array was successfully protected; otherwise, FALSE.
Remarks
ArrayProtect() protects array values from change once you assign values to them.
The function in which the array is declared can still write to the array.
Examples
This example stores values to array elements, protects the elements, then removes the protection so they can be changed by sub-functions:
X#
 1FUNCTION Start()
 2    LOCAL aWriteProtect AS ARRAY
 3    aWriteProtect := ArrayCreate(2)
 4    ArrayPut(aWriteProtect, 1, "Origin")
 5    ArrayPut(aWriteProtect, 2, "Origin")
 6    ArrayProtect(aWriteProtect)
 7    // Write allowed in calling function
 8    ArrayPut(aWriteProtect, 1, "Main Function")
 9    // Write not allowed in called function
10    TryChange(aWriteProtect)
11    ArrayDeprotect(aWriteProtect)
12    // Write allowed (no protection)
13    TryChange(aWriteProtect)
14FUNCTION TryChange(aPassed)
15    ArrayPut(aPassed, 1, "Sub Function")
See Also