Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

delphi - Fail to call overloaded function from another unit

I have a problem with an overloaded function. In its simplest form, try this:

unit Udefs;
interface uses classes;

procedure testOvld(var values : array of string; N : integer; comp : TlistSortCompare = nil); overload;
procedure testOvld(var values : array of string; comp : TlistSortCompare = nil); overload;

implementation
    
procedure testOvld(var values : array of string; N : integer; comp : TlistSortCompare = nil); overload;
begin
  // do something
end;

procedure testOvld(var values : array of string; comp : TlistSortCompare = nil); overload;
begin
  // do something
end;

end.

//

unit Ucalls;
interface
implementation uses Udefs;

function compare(left, right : pointer) : integer;
begin
end;

var
  S : array of string;
begin
  testOvld(S, compare)
end;

end.

It will not compile, with error:

not enough actual parameters

The problem does not show up when the values array is of type byte, double, or TObject. Neither will there be a problem when the two units are merged. (All of unit Ucalls' implementation section added to unit Udefs' implementation section.) I guess this is a compiler error in XE.

Is there a way around this, so that I can keep the function definition in its own unit?

question from:https://stackoverflow.com/questions/65864853/fail-to-call-overloaded-function-from-another-unit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...