Click or drag to resize

ArrayProtectT Function (Array OfT)

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.10
Syntax
 FUNCTION ArrayProtect<T>(
	aTarget AS ARRAY OF<T>
)
WHERE T : NEW()
 AS LOGIC
View Source

Parameters

aTarget
Type: Array OfT
The array to protect.

Type Parameters

T
The type of the array elements

Return Value

Type: Boolean
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#
FUNCTION Start()
        LOCAL aWriteProtect AS ARRAY
        aWriteProtect := ArrayCreate(2)
        ArrayPut(aWriteProtect, 1, "Origin")
        ArrayPut(aWriteProtect, 2, "Origin")
        ArrayProtect(aWriteProtect)
        // Write allowed in calling function
        ArrayPut(aWriteProtect, 1, "Main Function")
        // Write not allowed in called function
        TryChange(aWriteProtect)
        ArrayDeprotect(aWriteProtect)
        // Write allowed (no protection)
        TryChange(aWriteProtect)
FUNCTION TryChange(aPassed)
        ArrayPut(aPassed, 1, "Sub Function")
See Also