Referencing entities in descendants
When you declare a variable whose datatype is a kind of object,
such as a window, you can use the variable to reference any entity
defined in the object, but not in one of its descendants. Consider
the following code:
|
1 |
w_customer mycust<br /> <br /> Open(mycust)<br /> // The following statement is legal if<br /> // w_customer window has a st_name control.<br /> mycust.st_name.text = "Joe" |
mycust is declared as a variable of type w_customer (mycust is
a w_customer window). If w_customer contains
a StaticText control named st_name,
then the last statement shown above is legal.
However, consider the following case:
|
1 |
window newwin<br /> string winname = "w_customer"<br /> Open(newwin, winname)<br /> // Illegal because objects of type Window<br /> // do not have a StaticText control st_name<br /> newwin.st_name.text = "Joe" |
Here, newwin is defined as a variable
of type window. PowerBuilder rejects the above code because the
compiler uses what is called strong type checking: the PowerBuilder
compiler does not allow you to reference any entity for an object that
is not explicitly part of the variable’s compile-time datatype.
Because objects of type window do not contain a st_name control,
the statement is not allowed. You would need to do one of the following:
- Change the declaration of newwin to
be a w_customer (or an ancestor window
that also contains a st_name control),
such as:1w_customer newwin<br /> string winname = "w_customer"<br /> <br /> Open(newwin, winname)<br /> // Legal now<br /> newwin.st_name.text = "Joe" - Define another variable, of type w_customer,
and assign it to newwin, such as:1window newwin<br /> w_customer custwin<br /> stringwinname = "w_customer"<br /> <br /> Open(newwin, winname)<br /> custwin = newwin<br /> // Legal now<br /> custwin.st_name.text = "Joe"