Advanced PowerBuilder

HomePrevious Lesson: Sending Messages
Next Lesson: Function Overloading Using Inheritance

Function Overloading

Function overloading allows you to use the same function name to get different sets of results/behavior from the script. PowerBuilder allows this flexibility by responding to the parameters that are sent with the function call.

As an example of how function overloading works, let's look at PowerBuilder's MessageBox() function. This function allows you to output to the screen, via a dialog box, a string, a numeric or a boolean value. Usually, you would need to develop three nearly identical scripts to handle this functionality, but by using function overloading you can achieve the same result with only little effort.

The compiler identifies the version of the function to use depending on one of the arguments that must be passed to it, which in this case is the text parameter. This allows you to use a small function set, with great range of functionality. The disadvantage is its run-time overhead. Each time the function is called, the compiler has to find the appropriate function, depending on the arguments passed.

In PowerBuilder, function overloading can be done in two ways: inheritance or external functions. With version 5.0, you can overload the function without using inheritance.
HomePrevious Lesson: Sending Messages
Next Lesson: Function Overloading Using Inheritance