Recent

Author Topic: Overloaded procedure  (Read 3752 times)

Guionardo Furlan

  • New Member
  • *
  • Posts: 18
    • Guionardo Furlan
Overloaded procedure
« on: June 29, 2011, 02:20:43 am »
Hi there.

I've a set of overloaded procedures like this:

Show is a procedure that prints a value in a formatted way.

Code: [Select]
procedure Show(const AValue: string); overload; // no format
procedure Show(const AValue: TDateTime); overload; // formatdatetime
procedure Show(const AValue: Double); overload; // floattostr

The problem is that TDatetime is a Double, and the compiler can't do the distinction: unit1.pas(44,15) Error: Can't determine which overloaded function to call

This is the wrong way to do?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Overloaded procedure
« Reply #1 on: June 29, 2011, 08:06:42 am »
The solution is to rename the date version to something like:

procedure ShowDate(const AValue: TDateTime);

Guionardo Furlan

  • New Member
  • *
  • Posts: 18
    • Guionardo Furlan
Re: Overloaded procedure
« Reply #2 on: June 29, 2011, 02:26:45 pm »
Thanks.

 

TinyPortal © 2005-2018