Vector_replace |
Homepage Containers |
Replaces the element stored at the specific position with the new object.
ClassObject := Vector_replace(VectorObject, index, object = 0)
| VectorObject | The Vector 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 VectorObject 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 Vector_set, instead, if you wish to destroy the previous object.
Index values start at 1 and "wrap".
Vector_set, Vector_remove, Vector_discard
;You can use Vector_replace to move an object elsewhere. ;Creates a new Vector with the default parameters. myVector := Vector_new() ;Creates another Vector. myVector2 := Vector_new() ;Adds a String object to myVector. aString := String_new("Hello World!") Vector_add(myVector, aString) ;Replaces myVector[1] with a new object (returning the old). aString2 := String_new("Item1") oldObject := Vector_replace(myVector, 1, aString2) ;Since the object is not destroyed, it can be added elsewhere. Vector_add(myVector2, oldObject) ;Outputs the items. ;myVector[1] = "Item1" ;myVector2[1] = "Hello World!" MsgBox, % "myVector, index 1: " . Vector_get(myVector, 1) . "`n" . "myVector2, index 1: " . Vector_get(myVector2, 1)