Array_replace |
Homepage Containers |
Replaces the element stored at the specific position with the new object.
ClassObject := Array_replace(ArrayObject, index, object = 0)
| ArrayObject | The Array object to use for the current operation. |
| index | Index of element to replace. |
| object | The class object to store at the specified position. |
If there is no object set at the specified position, 0 is returned.
If ArrayObject is NULL (0 or blank), the empty string is returned, to indicate an error.
When replacing an object, the previous one is not destroyed (its lock count is still decreased to reflect the removal). Call Array_set, instead, if you wish to destroy the previous object.
Index values start at 1 and "wrap".
;You can use Array_replace to move an object elsewhere. ;Creates a new Array. myArray := Array_new(10) ;Creates another Array. myArray2 := Array_new(10) ;Sets myArray[1] to aString. aString := String_new("Hello World!") Array_set(myArray, 1, aString) ;Replaces myArray[1] with a new object (returning the old). aString2 := String_new("Item1") oldObject := Array_replace(myArray, 1, aString2) ;Since the object is not destroyed, it can be added elsewhere. Array_set(myArray2, 1, oldObject) ;Outputs the items. ;myArray[1] = "Item1" ;myArray2[1] = "Hello World!" MsgBox, % "myArray, index 1: " . Array_get(myArray, 1) . "`n" . "myArray2, index 1: " . Array_get(myArray2, 1)