IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphi  Print This     

Overloading

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:   overload

Delphi supports both method and operator overloading.

For method overloading, you use the overload keyword (all versions of the routine must include the overload keyword). The compiler chooses the correct method first based on the number of parameters, then on the type so you can have two overloaded methods with the same number of parameters so long as at least one parameter is different.

Another form of method overloading is with the use of default parameters, a shortcut syntax, where you specify a default parameter value.

Delphi also supports operator overloading with some operators.

Syntax Example:
function Add(a, b: integer): Integer;  overload;
begin
Result := a+b;
end;
  
function Add(const msg: String; a, b: integer): String; overload;
begin
  Result := msg + IntToStr(a+b);
end;




Cross Reference Examples:

Access VBA:   Not Supported

Some developers like to pass in an array and then handle the array for a pseudo technique but that's not really overloading.

ASP Classic:   Not Supported

ASP Classic does not support any type of overloading.

  • Operator - No.
  • Method - No.

Some developers like to pass in an array and then handle the array for a pseudo technique. Although not overloading, it's useful.

C#:   implicit

C# supports both method and operator overloading.

For methods, C# supports implicit overloading (no need for an overload keyword).

C++: 

C++ Overloading

  • Operator - Yes for C++, no for C. Almost all operators can be overloaded for user-defined types
  • Method -
Corel Paradox: 

Paradox & Overloading

  • Operator - No.
  • Method - No.

However, you can have the same named method or procedure so long as they are in different libraries. This is important if you use libraries in a class-like OOP way and wish to implement some form of polymorphism (i.e. libMember.Open and libVendor.Open). This is an OOP-like technique for implementing a subtyping-like polymorphism which is also known as inclusion polymorphism.

Also, some developers like to pass an array and then handle the array for a pseudo technique. Although not overloading, it's useful.

Delphi Prism:   implicit

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;
Java: 

Java Overloading

  • Operator - No. Sun deliberately chose not include operator overloading in the Java language.
  • Method - Yes.
JavaScript: 

JavaScript Overloading

  • Operator - No.
  • Method -
Syntax Example:

 

Perl: 

Perl

  • Operator - Yes
  • Method -
PHP: 

PHP

  • Operator - No.
  • Method -
Syntax Example:

 

VB Classic:   Not Supported

Developer defined overloading in VB Classic:

  • Operator - No
  • Method - No
VB.Net:   Overloads, or implicit

VB.Net supports both method and operator overloading.

For method overloading, you either use implicit overloading (no special syntax like C#) or use the Overloads keyword. If you use the Overloads keyword, all overloaded methods with the same name in the same class must include the Overloads keyword.





Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]