Passing objects
When you pass an object to a function or event, the object
must exist when you refer to its properties and functions. If you
call the function but the object has been destroyed, you get the
execution error for a null object reference. This is true whether
you pass by reference, by value, or read-only.
To illustrate, suppose you have a window with a SingleLineEdit.
If you post a function in the window’s Close event and
pass the SingleLineEdit, the object does not exist when the function
executes. To use information from the SingleLineEdit, you must pass
the information itself, such as the object’s text, rather
than the object. When passing an object, you never get another copy
of the object. By reference and by value affect the object reference,
not the object itself.
Objects passed by value
When you pass an object by value, you pass a copy of the reference
to the object. That reference is still pointing to the original
object. If you change properties of the object, you are changing
the original object. However, you can change the value of the variable
so that it points to another object without affecting the original
variable.
Objects passed by reference
When you pass an object by reference, you pass a pointer to
the original reference to the object. Again, if you change properties
of the object, you are changing the original object. You can change
the value of the variable that was passed, but the result is different—the
original reference now points to the new object.
Objects passed as read-only
When you pass an object as read-only, you get a copy of the
reference to the object. You cannot change the reference to point
to a new object (because read–only is equivalent to a CONSTANT declaration),
but you can change properties of the object.