Assignment for autoinstantiated user objects – PB Docs 126

Assignment for autoinstantiated user objects

Declaring an autoinstantiated user object creates an instance
of that object (just like a structure). The CREATE statement
is not allowed for objects with the Autoinstantiate setting. In
the following example, uo_emp_data has
the Autoinstantiate setting:

When you assign an autoinstantiated object to another autoinstantiated
object, the whole object is copied to the second
variable:

You never have multiple references to an autoinstantiated
user object.

Passing to a function

When you pass an autoinstantiated user object to a function,
it behaves like a structure:

  • Passing
    by value passes a copy of the object.

  • Passing by reference passes a pointer to the object
    variable, just as for any standard datatype.

  • Passing as read-only passes a copy of the object
    but that copy cannot be modified.

Restrictions for copying

Assignments are allowed between autoinstantiated user objects
only if the object types match or if the target is a nonautoinstantiated
ancestor.

Rule 1

If you assign one autoinstantiated object to another, they
must be of the same type.

Rule 2

If you assign an autoinstantiated descendent object to an
ancestor variable, the ancestor cannot have
the Autoinstantiate setting. The ancestor variable will contain
a reference to a copy of its descendant.

Rule 3

If you assign an ancestor object to a descendent variable,
the ancestor must contain an instance of the descendant or an execution
error occurs.

Examples

To illustrate, suppose you have these declarations. Uo_emp_active and uo_emp_inactive are
autoinstantiated objects that are descendants of non-autoinstantiated uo_emp_data:

Example of rule 1

When assigning one instance to another from the user objects
declared above, some assignments are not allowed by the compiler:

Example of rule 2

After this assignment, uo_emp1 contains
a copy of the descendent object uo_empa. Uo_emp_data (the
type for uo_emp1) must not be autoinstantiated.
Otherwise, the assignment violates rule 1. If uo_emp1 is autoinstantiated,
a compiler error occurs:

Example of rule 3

This assignment is only allowed if uo_emp1 contains
an instance of its descendant uo_empa,
which it would if the previous assignment had occurred before this
one:

If it did not contain an instance of target descendent type,
an execution error would occur.

For more information about passing arguments
to functions and events, see “Passing arguments to functions
and events”
.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x