I.T. Discussion Community!
-Collapse +Expand
Search Prism Group:

-Collapse +Expand Prism To/From
-Collapse +Expand Prism Study Test
-Collapse +Expand Prism Store

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi PrismLanguage Det...   Print This     
  From the January 2016 Issue of Prestwood eMag
Prism Language Details:
Delphi Prism Overloading (implicit)
Posted 10 years ago on 2/13/2009
Prism Code Snippet:
 A flashcard from our Prism Flashcards Library
 A code snippet from our Prism Code Snippets Page


General Info: 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 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;
Result := a + b;
method MainForm.Add(const msg: String; a, b: integer): String;
Result := msg + (a + b);

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.

  1. Create an application with a single form and button.
  2. Alter the form class in the interface section as follows:
    MainForm = partial class(System.Windows.Forms.Form)
      method button1_Click(sender: System.Object; e: System.EventArgs);
      method Dispose(disposing: Boolean); override;
      method Add(a, b: integer): Integer;
      method Add(const msg: String; a, b: integer): String;


  3. Add the two methods to the implementation section:
    method MainForm.Add(a, b: integer): Integer;
      Result := a + b;
    method MainForm.Add(const msg: String; a, b: integer): String;
      Result := msg + (a + b);

  4. Now exercise our overloaded method. Alter the click event of our button as follows:
    method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
      MessageBox.Show("2 + 2 = " + Add(2,2));


  5. Test-it. Run the application and click the button.

More Info

Definition:  Overloading


Share a thought or comment...
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1215A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101903 Counter
Since 2/13/2009
   Contact Us!
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,374 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...

©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech