Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Overload question



Permlink Replies: 4 - Last Post: Jun 2, 2017 9:59 AM Last Post By: Remy Lebeau (Te...
Markus Humm

Posts: 5,113
Registered: 11/9/03
Overload question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:00 PM
Hello,

in some code I sort of inherited I find the two following procedure
declaratrions:

function CRCCode(var CRCDef: TCRCDef;
                 const Buffer;
                 Size: UInt32): UInt32; overload;
 
function CRCCode(var CRCDef: TCRCDef;
                 ReadMethod: TReadMethod;
                 Size: UInt32 = $FFFFFFFF;
                 Dummy: Boolean = False): UInt32; overload;


TReadMethod is a method reference and TCRCDef a packed record.

In the original code there is some comment about the Dummy parameter
being there for older Delphi versions (e.g. D7) so that the compiler can
distinguish them and call the correct one.

I'm wondering whether I still need this otherwise unused parameter
in D2009+?
I'm asking because my development system is Berlin and I don't have
D2009 installed anymore.

Greetings

Markus
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Overload question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:48 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

I'm wondering whether I still need this otherwise unused parameter
in D2009+?

Unless old compilers would pass a class method to the untyped 'const'
parameter instead of the TReadMethof parameter, I don't see why the
Dummy parameter was needed at all. It is cetainly not needed in modern
versions.

--
Remy Lebeau (TeamB)
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Overload question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:53 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Am 01.06.2017 um 22:48 schrieb Remy Lebeau (TeamB):
Markus Humm wrote:

I'm wondering whether I still need this otherwise unused parameter
in D2009+?

Unless old compilers would pass a class method to the untyped 'const'
parameter instead of the TReadMethof parameter, I don't see why the
Dummy parameter was needed at all. It is cetainly not needed in modern
versions.

Thanks, I can get rid of that then.

Greetings

Markus
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: Overload question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 5:20 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Hello,

in some code I sort of inherited I find the two following procedure
declaratrions:

function CRCCode(var CRCDef: TCRCDef;
                 const Buffer;
                 Size: UInt32): UInt32; overload;
 
function CRCCode(var CRCDef: TCRCDef;
                 ReadMethod: TReadMethod;
                 Size: UInt32 = $FFFFFFFF;
                 Dummy: Boolean = False): UInt32; overload;


TReadMethod is a method reference and TCRCDef a packed record.

In the original code there is some comment about the Dummy parameter
being there for older Delphi versions (e.g. D7) so that the compiler
can distinguish them and call the correct one.

I'm wondering whether I still need this otherwise unused parameter
in D2009+?

I think so. Buffer is an untyped variable, so you can pass many things
to it, even a method pointer. So a call with three parameters,
TCRCDef, TReadMethod and UInt32 would be ambiguous. That is why you
probably still need the dummy Boolean.

--
Rudy Velthuis http://www.rvelthuis.de

"It makes no difference as to the name of the God, since love
is the real God of all in the world."
-- Apache
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Overload question
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 2, 2017 9:59 AM   in response to: Rudy Velthuis (... in response to: Rudy Velthuis (...
Rudy Velthuis (TeamB) wrote:

Buffer is an untyped variable, so you can pass many things
to it, even a method pointer. So a call with three parameters,
TCRCDef, TReadMethod and UInt32 would be ambiguous.

Not really, since a method pointer would be a better match for
TReadMethod than an untyped parameter, so the compiler is more likely
to pick that overload. And that is exactly what happens in modern
compiler versions (well, in XE2, anyway. I didn't test other versions).

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02