Embedded Objects
ObjectTools allows you to embed objects within objects. This lets you create hierarchically structured representations of heterogeneous data. An object stored within another object has a distinct item type (not Is Longint) to identify it as such.
Here’s what a complex object might look like. Indentation denotes embedded objects:
Tag Type Contents
| "fields" | Object | |
|---|---|---|
| "firstname" | Character | "John" |
| "lastname" | Character | "Doe" |
| "dialog" | Object | |
| "table" | Pointer | ->[Contacts] |
| "form" | Character | "Input" |
| "left" | Longint | 200 |
| "top" | Longint | 200 |
| "width" | Longint | 350 |
| "height" | Longint | 300 |
| "title" | Character | "Contact Entry" |
Here’s the code to create this object:
C_LONGINT($object;$fields;$dialog) $object:=OT New
OT PutString ($object;"fields.firstname";"John") OT PutString ($object;"fields.lastname";"Doe")
OT PutPointer ($object;"dialog.table";->[Forms]) OT PuString ($object;"dialog.form";"ContactInput") OT PutLong ($object;"dialog.left";200)
`And so on
As you can see from the above example, ObjectTools automatically creates embedded objects as necessary if they appear in the tag and don’t yet in the object.
Accessing Embedded Objects
To access the "firstname" item in the "fields" Object, you would use:
$firstName:= OT GetString ($object;"fields.firstname")
This is what you would expect. But how would you access the "table" item in the embedded "dialog" object?
Embedded items are accessed using dot notation. Given an embedded object "foo", you access items within that object with the tag "foo.<item tag>".
So, for example, to access the "table" item inside the "dialog" object defined above, you would use:
C_POINTER($table)
OT GetPointer ($object;"dialog.table";$table)
If objects are nested more than one level deep, you just continue adding dots. So to access an item called "bar" inside an embedded object called "foo" inside an embedded object called "foobar", you would use "foobar.foo.bar".

