Delphi Ambiguous overloaded call in MkDir

When trying to call MkDir

you receive the following error message:

[Error] DBaseReindexer.dpr (22): ambiguous overloaded call 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 is a version that takes a string, and a version that takes a PChar. I am not sure how my string would be ambiguous between these two types.


Code to reproduce the error (from comments):

program Project1; 
{$APPTYPE CONSOLE} 
uses SysUtils, System; 
begin 
  MkDir('Test');  
end.

      

+3


source to share


1 answer


Your code is compiled 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 in your code you have defined an incompatible overload for MkDir

. For example, 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.

      

creates 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 helps you, which two methods cannot be eliminated. If you read the complete compiler error message it will lead you to the cause of your problem.

Older versions of Delphi don't give you more information. Therefore, if you are in this position, you will have to search the source code for additional MkDir

.



Update

After editing the question adding code, we can see that the incompatible overloading comes from a rather surprising source. Your code:

program Project1; 
{$APPTYPE CONSOLE} 
uses SysUtils, System; 
begin 
  MkDir('Test');  
end.

      

Well, it's System

automatically included in every unit and it's a compiler defect that the compiler goes through after the sentence uses

. But the erroneous second inclusion System

is the cause of the ambiguity.

Modern Delphi versions fix this problem and your code results in

[dcc32 Error] E2004 Identifier redeclared: 'System'

Obviously the solution is to remove the false use System

.

+5


source







All Articles