Referencing entities in descendants
When you declare a variable whose data type 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 |
1 |
1 |
Open(mycust) |
1 |
// The following statement is legal if |
1 |
// w_customer window has a st_name control. |
1 |
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 |
1 |
string winname = "w_customer" |
1 |
1 |
Open(newwin, winname) |
1 |
// Illegal because objects of type Window |
1 |
// do not have a StaticText control st_name |
1 |
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
data
type.
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
1string winname = "w_customer"
1
1Open(newwin, winname)
1// Legal now
1newwin.st_name.text = "Joe" - Define another variable, of type w_customer,
and assign it to newwin, such as:1window newwin
1w_customer custwin
1stringwinname = "w_customer"
1
1Open(newwin, winname)
1custwin = newwin
1// Legal now
1custwin.st_name.text = "Joe"