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:

w_customer mycust

Open(mycust)
// The following statement is legal if
// w_customer window has a st_name control.
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:

window newwin
string winname = "w_customer"
Open(newwin, winname)
// Illegal because objects of type Window
// do not have a StaticText control st_name
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:

    w_customer newwin
    string winname = "w_customer"
    
    Open(newwin, winname)
    // Legal now
    newwin.st_name.text = "Joe"
  • Define another variable, of type w_customer, and assign it to newwin, such as:

    window newwin
    w_customer custwin
    string winname = "w_customer"
    
    Open(newwin, winname)
    custwin = newwin
    // Legal now
    custwin.st_name.text = "Joe"