Assigning Structures to Structures or Variants and vice versa

ATEasy allows a special assignment operation with structures, namely Assigning Structures to Variants and vice versa.  Between same type of structures, you can also make assignments.

Assigning Structures to Structures

Instead of assigning individual fields, you can assign structures to another structures as long as they are of same type.  For example,

 

! testexec options
stUserGroup.stOptions=m_stData.stOptions

where stOptions is a structure and it is a field of s structure stUserGroup.

Assigning Structures to Variants and vice versa (ATEasy version 5)

In many of ATEasy controls objects, there is a property called Tag which is of type Variant.  You can assign a structure to the tag property. Or you can assign an array of variants to the tag and you can assign different structures to each variant element - which means you can not only store as much data but also many different data in a field, tag.  You can successfully retrieve data to a structure by the reverse order of assigning operations.

The following describes this assignment operation and rules it abides:

        When a structure is assigned to a variant, the resulting value of the variant is an array of variants.  The number of elements in the array is the number of fields in the structure. Each field in the structure is assigned to the corresponding element of the variant array. A field can be itself a structure - which will be stored as an array of Variants and so on.

        A Variant containing an array of Variants can be assigned to a structure - which is the reverse operation.  Each element in the variant array is assigned to the corresponding field in the structure.  The assignment will stop when either there is no more element in the variant or there is no more field in the structure definition.

Comments

 Since the number of elements in the array of variants does not have to match with the number of fields in a structure and the reverse assignment (from a variant to a structure) stops at the smaller number of the two, the implication is that you can add or delete fields at the end of structure without causing any errors.

Furthermore, the variant containing an array of variants can be assigned to even a different structure as long as each individual field assignment is legal.  In general, any numeric variant value can be assigned to any ATEasy numeric type, a vtBStr variant value can be assigned to any ATEasy String or BString, and a vtDispatch or vtUnknown variant value can be assigned to an ATEasy Object type.

Example

In the following example, we have an array of variants and its size is 1.  The first variant element is set to a structure, stUsersTag.  Then to users.Tag we assign the array.

avInfo[0]=stUsersTag
users.Tag=avInfo

To retrieve the info,

avInfo=users.Tag
stUsersTag=avrInfo[0]

As we mentioned, the above statements will be just fine even after you add some fields to the structure at the end, stUsersTag during the course of development.