Array_get |
Homepage Containers |
Returns the value for the object stored in the Array at the specified position.
value := Array_get(ArrayObject, index, useFunction = "")
| ArrayObject | The Array object to use for the current operation. |
| index | Index of element whose value is returned. |
| useFunction | If specified, this is the function to call on the object. For example, if useFunction were "size", and the object at the specified index is an Array, Array_size(object) would be called; whereas if the object were a Vector, Vector_size(object) is called. Note: the passed object is the object at the specified index in this Vector. Also, the function is called by passing only one argument, the object. As such, this feature is primarily used to retrieve a field in the object (e.g. the size). Additionally, if the specified object is a wrapper object, it will not be unwrapped first. |
If the object at the specified position is a wrapper, then its contents are "unwrapped" and returned.
Otherwise, the address for the object is returned.
If useFunction is specified, the function with the same name located inside of the object's class will be dynamically called, and its return will be returned.
If ArrayObject is NULL (0 or blank), the empty string is returned, to indicate an error.
To always get the address of a Class object, even for Wrapper objects, call Array_getAddress instead.
Index values start at 1 and "wrap".
;Creates a new Array (of length 10). myArray := Array_new(10) ;Sets myArray[1] to a String object (Wrapper). aString := String_new("Hello World!") Array_set(myArray, 1, aString) ;Sets myArray[2] to an Array object (Non-Wrapper). anArray := Array_new(15) Array_set(myArray, 2, anArray) ;Unwraps the String object and returns "Hello World!" MsgBox, % "The unwrapped String: " . Array_get(myArray, 1) ;Since Array is not a Wrapper class, the object's address is returned instead. MsgBox, % "The Array's address: " . Array_get(myArray, 2)