Object Fields are like record fields. They are accessed in the same way as a record field would be accessed : by using a qualified identifier. Given the following declaration:
then the following would be a valid assignment:
Inside methods, fields can be accessed using the short identifier:
Or, one can use the self identifier. The self identifier refers to the current instance of the object:
One cannot access fields that are in a private or protected sections of an object from outside the objects’ methods. If this is attempted anyway, the compiler will complain about an unknown identifier.
It is also possible to use the with statement with an object instance, just as with a record:
In this example, between the begin and end, it is as if AnObject was prepended to the Afield and Amethod identifiers. More about this in section 13.2.8, page 657.