Overview​

With associative arrays it is possible to address an element in the array not by its ordinal (numeric) but by name (character string). The Xbase++ datatype array does not support this possibility.

However, objects of the class DataObject() semantically offer an identical usage, because the member variables of such an instance are managed dynamically.

Basic usage​

Xbase++:
oPerson := DataObject():new()
oPerson:FirstName    := "Jean-Luc"
oPerson:LastName     := "Picard"
oPerson:Birthplace   := "La Barre"
oPerson:Bithday      := SToD("23050713")

? oPerson:Phone      // -> NIL

The above example demonstrates that after instantiating a DataObject, you can read and write to member variables of any name. If no value has yet been assigned to a member variable, the read access returns NIL.

Universal access​

The names of member variables in Xbase++ are subject to restrictions. It is not allowed that names start with a digit or contain hyphens. In such cases the method :setNoIvar() and :getNoIvar() can be used for member access. Because the Xbase++ runtime does not need to dynamically resolve the name of the member variable, access via this interface is much faster.
Xbase++:
// Syntax error. Hyphon is not allowed in the name:
// oPerson:Fax-Number := "123456789"

oPerson:setNoIvar( "Fax-Number", "123456789" )
? oPerson:getNoIvar( "Fax-Number" )             // -> "123456789"