Resolving naming conflicts – PB Docs 70

Resolving naming conflicts

There are two areas in which name conflicts occur:

  • Variables that are
    defined within different scopes can have the same name. For example,
    a global variable can have the same name as a local or instance
    variable. The compiler will warn you of these conflicts, but you don’t
    have to change the names.
  • A descendent object has functions and events that
    are inherited from the ancestor and have the same names.

If you need to refer to a hidden variable or an ancestor’s
event or function, you can use dot notation qualifiers or the scope
operator.

Hidden instance variables

If an instance variable has the same name as a local, shared,
or global variable, qualify the instance variable with its object’s
name:

If a local variable and an instance variable of a window are
both named birthdate, then qualify the instance variable:

If a window script defines a local variable x, the name conflicts
with the X property of the window. Use a qualifier for the X property.
This statement compares the two:

Hidden global variables

If a global variable has the same name as a local or shared
variable, you can access the global variable with the scope operator
(::):

This expression compares a local variable with a global variable,
both named total:

note.gif Use prefixes to avoid naming conflicts If your naming conventions include prefixes that identify
the scope of the variable, then variables of different scopes will
always have different names and there will be no conflicts.

For more information about the search order
that determines how name conflicts are resolved, see the chapters
about declarations and calling functions and events in the PowerScript
Reference

.

Overridden functions and events

When you change the script for a function that is inherited,
you override the ancestor version of the function. For events, you
can choose to override or extend the ancestor event script in the
painter.

You can use the scope operator to call the ancestor version
of an overridden function or event. The ancestor class name, not
a variable, precedes the colons:

You can use the Super pronoun instead of naming an ancestor
class. Super refers to the object’s immediate ancestor:

In good object-oriented design, you would not want to call
ancestor scripts for other objects. It’s best to restrict
this type of call to the current object’s immediate ancestor
using Super.

For how to capture the return value of an
ancestor script, see “Return values from ancestor
scripts”
.

Overloaded functions

When you have several functions of the same name for the same
object, the function name is considered overloaded. PowerBuilder determines
which version of the function to call by comparing the signatures
of the function definitions with the signature of the function call.
The signature includes the function name, argument list, and return
value.


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