ComponentOne True DataControl 8.0
Manipulating Memory Arrays in Code

The Array property returns the XArrayDB object housing a TData control’s data. As several of the True DataControl tutorials demonstrate, you can use memory array mode without ever referring to the Array property in code. However, if you want to access the memory array directly, or set the Array property to your own XArrayDB object, you must first include a reference to the XArrayDB object in your project. To do this, select References... from the Visual Basic Project menu, check the box labeled ComonentOne XArrayDB Object, and click the OK button.

Note: It is not necessary to access the Array property in order to get or set field values. As in all other data modes, you can use the collection returned by the control's Fields property for that. You need to access the Array property only if you have to modify the whole contents of the underlying XArrayDB.

To declare an XArrayDB instance in code, write:

Example Title
Copy Code
Dim x As New XArrayDB

To allocate space for array elements, use the ReDim method, which is similar to the ReDim statement in Visual Basic:

Example Title
Copy Code
x.ReDim 1, 100, 1, 5 ' one-based array with 100 rows, 5 columns

The number of columns in your XArrayDB object must be equal to the number of data fields in the collection returned by the control’s Fields property.

Note that the ReDim method automatically preserves the contents of the XArrayDB. Uninitialized elements contain empty variants.

To access the elements of an XArrayDB object, use the same syntax as you would for a Visual Basic array:

Example Title
Copy Code
x(4,1) = "True DataControl" ' row 4, column 1; string data

x(4,2) = 199.95 ' row 4, column 2; floating point data

If IsEmpty(x(1,1)) Then

   MsgBox "First element is uninitialized"

End If

Note that XArrayDB elements are not restricted to one data type; any variant data type supported by Visual Basic can be used. However, when a bound control attempts to update a column, True DataControl will enforce any restrictions imposed by the data type of the corresponding field definition. For example, alphabetic data cannot be written to a numeric field.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback