wwDotNetBridge::AddArrayItem

Adds a new item to an array instance on an existing object. Increases the array size by 1.

If the array object instance doesn't exist the array is automatically created based on the array element type. In other words you shouldn't have to manually create the array with CreateArrayOnInstance() first.

Example:

DO wwDotNetBridge

loBridge = CREATEOBJECT("wwDotNetBridge")
loItem = loBridge.CreateInstance("TestApp.VfpTestClass")

*** Create a new person object
loPerson = loBridge.CreateInstance("TestApp.Person")
loPerson.Name = "Jim johnson"
loPerson.Company = "Temporary traders"

*** Add item to the array - if the array instance is null it's created
loBridge.AddArrayItem(loItem,"PersonArray",loPerson)

*** Check Length - 1
? loBridge.GetPropertyEx(loItem,"PersonArray.Length")

*** Get back the person object - note array is 0 based index!
loNewPerson = loBridge.GetArrayItem(loItem,"PersonArray",0)

? loNewPerson.Name
? loNewPerson.Company

*** This also works
loPersons = loItem.PersonArray
loNewPerson = loPersons[1] 
? loNewPerson.Name
o.AddArrayItem(loBaseObject,lcArrayProperty,loValue)

Return Value

.T. or .F.

Parameters

loBaseObject
The base object reference on which the Array property is defined.

lcArrayProperty
The name of the Array property on loBaseObject

loValue
The value to be set for the new item added.

Remarks

AddArrayItem() will create an array or resize an existing array and there's some overhead in this operation. If you know the size of the array prior to creating it it's more efficient to use CreateArrayOnInstance() with a preset size, and then use SetArrayItem() to assign the individual array items by index.


See also:

Class wwDotNetBridge | Accessing Arrays

© West Wind Technologies, 2004-2020 • Updated: 11/17/11
Comment or report problem with topic