0
votes

Consider this code :

  TForm3 = class(TForm)
  public
   class procedure GetAConn(var res:String); overload;
   class procedure GetAConn(var res:Integer);overload;
    { Public declarations }
  end;

class procedure TForm3.GetAConn(var res: String);
begin
 showmessage(res);
end;

class procedure TForm3.GetAConn(var res: Integer);
begin
 showmessage(IntToStr(res))
end;

which compiles without any problems.

Now, If I'm doing this :

procedure TForm3.FormCreate(Sender: TObject);
begin
 TForm3.GetAConn('aaa');
 TForm3.GetAConn(10);
end;

I get [DCC Error] Unit3.pas(64): E2250 There is no overloaded version of 'GetAConn' that can be called with these arguments.

I didn't find something about this being restricted in Delphi XE.

LE: is working in this way:

class procedure TForm3.GetAConn(var res: String);
begin
 res := res + 'modif';
end;

class procedure TForm3.GetAConn(var res: Integer);
begin
 res := res + 100;
end;
procedure TForm3.FormCreate(Sender: TObject);
var s:String;
    i:Integer;
begin
 s:='aaa';
 TForm3.GetAConn(s);
 showmessage(s);
 i:=10;
 TForm3.GetAConn(i);
 showmessage(IntToStr(i))
end;
1

1 Answers

6
votes

You're passing the parameters by reference. Drop the var and all should be well:

class procedure GetAConn(const res: String); overload;
class procedure GetAConn(res: Integer); overload;

(As you don't modify the string parameter I suggest passing it as const.)

If you indeed need reference parameters than you can't pass literals or constants, of course. But that has nothing to do with using overload. (Besides the fact that overloading obsfuscates the error message.)