I'm getting the following error message when I attempt to call MkDir
[Error] DBaseReindexer.dpr(22): Ambiguous overloaded call to
MkDir
I've tried the following things and they all return the same error.
MkDir('test');
var
Dir: String;
begin
Dir := 'test';
MkDir(Dir);
end;
const
Dir = 'test';
begin
MkDir(Dir);
end;
From looking at the source, there's a version that takes a string, and a version that takes a PChar. I'm not sure how my string would be ambiguous between those two types.
Code to reproduce the error (from comments):
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils, System;
begin
MkDir('Test');
end.
Your code compiles fine in an empty project:
program Project1;
procedure Test;
const
ConstStr = 'test';
var
VarStr: string;
begin
MkDir('Test');
MkDir(ConstStr);
MkDir(VarStr);
end;
begin
end.
So your problem is that somewhere else in your code you have defined an incompatible overload for MkDir
. For instance this program:
program Project1;
procedure MkDir(const S: string); overload;
begin
end;
procedure Test;
const
ConstStr = 'test';
var
VarStr: string;
begin
MkDir('Test');
MkDir(ConstStr);
MkDir(VarStr);
end;
begin
end.
produces the following compiler errors:
[dcc32 Error] Project1.dpr(13): E2251 Ambiguous overloaded call to 'MkDir' System.pas(5512): Related method: procedure MkDir(const string); Project1.dpr(3): Related method: procedure MkDir(const string); [dcc32 Error] Project1.dpr(14): E2251 Ambiguous overloaded call to 'MkDir' System.pas(5512): Related method: procedure MkDir(const string); Project1.dpr(3): Related method: procedure MkDir(const string); [dcc32 Error] Project1.dpr(15): E2251 Ambiguous overloaded call to 'MkDir' System.pas(5512): Related method: procedure MkDir(const string); Project1.dpr(3): Related method: procedure MkDir(const string);
Notice how the compiler helpfully tells you which two methods cannot be disambiguated. If you read the full compiler error message then it will take you to the cause of your problem.
Older Delphi versions don't give you the extra information. So if you are in that position, you will have to search your source code for the extra MkDir
.
Update
Following the edit to the question that adds code, we can see that the incompatible overload arises from a rather surprising source. Your code is:
program Project1;
{$APPTYPE CONSOLE}
uses SysUtils, System;
begin
MkDir('Test');
end.
Well, System
is automatically included in every unit and it is a compiler defect that the compiler gets past the uses
clause. But the erroneous second inclusion of System
is what is causing the ambiguity.
Modern versions of Delphi fix this problem and your code results in
[dcc32 Error] E2004 Identifier redeclared: 'System'
Clearly the solution is to remove the spurious use of System
.