We help IT Professionals succeed at work.

"There is no overloaded version..."

Wim ten Brink
on
1,104 Views
Last Modified: 2013-11-22
Create a new project, add this:

program Project1;
type TMessageEvent = procedure of object;
procedure Execute(OnMessage: TMessageEvent = nil); overload;
begin end;
begin
  Execute(nil);
end.

If you get the compiler message: [Error] Project1.dpr(11): There is no overloaded version of 'Execute' that can be called with these arguments
Then you get the same problem as I'm having in Delphi 6...

Now my problem... I need a way to fix this! And no, I am NOT allowed to change the procedure declaration. I am NOT allowed to change the type definition of TMessageEvent either. I am allowed the way how I call it, though. But this seems to be unfixable.
Comment
Watch Question

Russell LibbySoftware Engineer, Advisory
CERTIFIED EXPERT
Top Expert 2005

Commented:
The overload is throwing it, but I still don't understand why you don't call it like this:

program Project1;

type
  TMessageEvent  =  procedure of object;

procedure Execute(OnMessage: TMessageEvent = nil); overload;
begin
end;

begin
  Execute(); // <- dont pass anything, same as passing nil
end.

---

Russell
Why do you use overload at all? There is no second Execute procedure or function declared.
Wim ten BrinkSelf-employed developer
CERTIFIED EXPERT

Author

Commented:
Actually, the problem is that the real procedure that I'm trying to overload is more complex than this one. It's just an example of what causes this strange compiler-error. The real procedure happens to be a function:

function ExecuteEx(const FileName: string; const Params: string = ''; const DefaultPath: string = ''; const Options: TShellExecuteOptions = []; const OnShellExecuteWait: TOnShellExecuteWait = nil; const OnMessage: TMessageEvent = nil; const Handle: LongWord = 0; const ShowCmd: Integer = SW_SHOWNORMAL; const Operation: string = 'open'; const MustExist: Boolean = True): Boolean;

And this one has two method parameters. Even worse, this function is already in use in several different projects, and just altering the function parameters would require all those projects to be adjusted too. And no, I'm not going to do that...
However, I want a second ExecuteEx function which has one additional parameter at the beginning and it will return an integer, not a boolean. But I would like to use the same name. Unfortunately, that's not possible because I can't overload this function.
After some more investigations, I discovered that the simple example that I provided is enough to reproduce the error. So I just kept it simple. :-)

If I could re-adjust the function header then all I would have to do was to put those two method pointers at the end of the parameter list or use some other construction. But as I already indicated, this function is used heavily by several existing projects and we don't want to rebuild them all just to solve something Delphi can't handle, apparantly...

After declaring that second overloaded function, I might even decide to add a third, fourth and perhaps even more, depending on the need in future projects.

The fix for now is not using overloading...:-(
Software Engineer, Advisory
CERTIFIED EXPERT
Top Expert 2005
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Wim ten BrinkSelf-employed developer
CERTIFIED EXPERT

Author

Commented:
Thanks, I needed the discomfort of knowing that Delphi has yet another bug. :-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.