Types of overloading include method overloading and operator overloading.
Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.
Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.
Delphi Prism Overloading
Like Delphi, Prism supports overloading. However, Prism supports implicit overloading (no need for an overload keyword).
Syntax Example:
method MainForm.Add(a, b: integer): Integer; begin Result := a + b; end;
method MainForm.Add(const msg: String; a, b: integer): String; begin Result := msg + (a + b); end;
Delphi Prism Working Example
In the following demo, we will add the two overloaded methods above to a form class and use them in a button click event.
Create an application with a single form and button.
Alter the form class in the interface section as follows: