Understanding and Using Dot Variables
Description
After you create a pointer variable, you may add to it any number of "child" variables of different types. These are known as dot variables.
dim ptr as P dim ptr.lastname as C dim ptr.birthday as D dim ptr.age as N dim ptr.spouse as P dim ptr.spouse.firstname as C dim ptr.children[3] as P dim ptr.children[3].firstname as C dim ptr.children[3].age as N
As the sample code above illustrates, a pointer variable may have pointers as child variables. These variables, can have their own child variables of any type. Any variable can also be created as an array with multiple elements. One benefit of dot variables is that you may send the whole family of variables to a function (in this case named foo ) by simply sending the base level pointer variable ( ptr ).
foo(ptr)
In this example the foo() function can read and write ptr.birthday, ptr.spouse.firstname, or any of the other child variables.
Setting Dot Variable Properties Dynamically
Using dotVarSet() lets you build flexible and data-driven applications where the structure of your dot variables can be determined dynamically. This can simplify form processing, API integrations, and more.
dim p as P
dim prop as C = "dob"
dim val as D = {12/18/1972}
dotVarSet(p, prop, val)
? p.dob ' Outputs: 12/18/1972Getting Dot Variable Properties Dynamically
dotVarGet() allows you to dynamically read values from a dot variable structure. It complements dotVarSet() and is especially useful when accessing fields by name from external sources like forms or JSON payloads.
dim p as P p.age = 35 dim propName as C = "age" dim result as N = dotVarGet(p, propName) ? result ' Outputs: 35
Another Example of dotVarGet()
You can use dotVarGet() with any data type, including dates, strings, and numbers.
dim p as P
dim property as C = "dob"
dim value as D = {12/18/1972}
dotVarSet(p, property, value)
dim result as A
result = dotVarGet(p, property)
? result ' Outputs: 12/18/1972See Also