This method creates a new instance of a one dimensional array on an existing .NET object.

You can pass in either a numeric size in which case the array is created uninitialized (ie. each of the items are null or default .NET values). If you pass in any non-numeric value for the third parameter a 1 element array is created with the first element set to the item passed in.

Note that AddArrayItem() can perform the same task as this method as it too can create the array if it doesn't exist.

Due to limitations in how VFP handles .NET arrays arrays must always be defined on an object and can't be directly accessed as objects in VFP. For this reason the syntax requires both the base object reference and the array property as a string.

loBridge = CREATEOBJECT("wwDotNetBridge")

*** Create a .NET class that has PersonArray Property
loItem = loBridge.CreateInstance("Westwind.WebConnection.VfpTestClass")

*** Create an array with 2 elements 
? loBridge.CreateArrayOnInstance(loItem,"PersonArray",2)

loPerson = loBridge.GetArrayItem(loItem,"PersonArray",0)
loPerson.Name = "Rick"

loPerson2 = loBridge.GetArrayItem(loItem,"PersonArray",1)
loPerson2.Name = "Jim"

*** This works too

*** Set two array items

Alternately you can pass an object for the third parameter and create a one element array with a value assigned, then use AddArrayItem to add more items:

loBridge = CREATEOBJECT("wwDotNetBridge")
loItem = loBridge.CreateInstance("Westwind.WebConnection.VfpTestClass")

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

*** Create 1 element array and add the new person object
loPerson = loBridge.GetArrayItem(loItem,"PersonArray",0)
? loPerson.Name
? loPerson.Company

loPerson = loBridge.CreateInstance("Westwind.WebConnection.Person")
loPerson.Name = "Billy Bopp"
loPerson.Company = "Boppers Inc."


*** Length of the array - 2
? loBridge.GetPropertyEx(loItem,"PersonArray.Length")

*** Get the second item and display
loPerson = loBridge.GetArrayItem(loItem,"PersonArray",1)
? loPerson.Name
? loPerson.Company

The first mechanism will be more efficient as it pre-allocates the array in .NET. The latter approach is easier to write, but it causes the array to be copied in order to allow resizing of the array dynamically.

o.CreateArrayOnInstance(loBaseObject, lcArrayProperty, [lnSize | loData])

Return Value

.T. or .F.


The .NET object instance that contains the array member.

The name of the property on loBaseObject that is the array.

lnSize | loData
This parameter is variable: If a numeric value is passed the array is sized to the specified value with all items uninitialized. If anything but a number is passed a 1 element array is created and the first data item is set to loData

See also:

Class wwDotNetBridge | Accessing Arrays | wwDotNetBridge::AddArrayItem

© West Wind Technologies, 1996-2021 • Updated: 02/07/14
Comment or report problem with topic