Solved

Ambiguous overloaded call to ...

Posted on 2004-04-15
3
1,151 Views
Last Modified: 2011-10-03
I'm trying to write an overloaded function that can return data as different types. Basically the function I will altimately be calling will return a string, hoever I want to write a wrapper around this so that I can get results in other types (Integer, real, etc..)

Heres my example.. When I try to compile this, I get "Ambiguous overloaded call to 'DBGetValue'.. What am I doing wrong here?

function DBGetValue(Module,Key:String):String; overload;
begin
  Result := '12345';
end;

function DBGetValue(Module,Key:String; const Default:Integer = 0): Integer; overload;
var s:String;
begin
  try
    s      := DBGetValue(Module,Key);
    Result := StrToInt(s);
      except
      Result := Default;
    end;
end;
0
Comment
Question by:rbohac
  • 2
3 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 10836939
I suspect that it's getting confused by the recursive nature of the call (DBGetValue within DBGetValue). Perhaps you should name the wrappers DBGetValue and the underlying function DBGetValueBase.
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 10837495

Its abiguous because you defined the second call with a default value, meaning the integer param is not required to be passed, so it can't tell the difference between the first and the second definition.

If you code it as:

function DBGetValue(Module,Key:String; const Default: Integer): Integer; overload;

Then it quits complaining.

Regards,
Russell
0
 
LVL 7

Expert Comment

by:sftweng
ID: 10837514
Doh! Of course.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now