Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Overloading/Method    [ Add a report in this area ]  
Report #:  35009   Status: Open
Overload function will not accept nil in function pointer parameter.
Project:  Delphi Build #:  10.0.2288.42451
Version:    10.0 Submitted By:   Tim Burrows
Report Type:  Basic functionality failure Date Reported:  10/9/2006 2:23:38 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   243017
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 10
Description
The compiler does not seem to like a function pointer variable being passed in as nil on an overloaded function. See 'Steps' to replicate.

Example:

procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String); overload;
procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String; const w_Test3: Boolean);

When calling TestB I cannot pass nil into the function. But I can if it's not overloaded.

The error :

E2250 There is no overloaded version of '[func]' that can be called with these arguments.
Steps to Reproduce:
Create a form.

Add a button.

------------- Add the following type ------------------

TTestFunc = function(w_Test: String): Boolean of object;

-------------- Add the following function declaration in the Interface section ----------------

procedure Test(const w_Test: String; w_Func: TTestFunc);
procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String); overload;
procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String; const w_Test3: Boolean); overload;

------------ Add the implementation -------------------

procedure Test(const w_Test: String; w_Func: TTestFunc);
begin
  MessageDlg('Test', mtInformation, [mbOk], 0);
end;

procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String); overload;
begin
  MessageDlg('TestB-A', mtInformation, [mbOk], 0);
end;

procedure TestB(const w_Test: String; w_Func: TTestFunc; const w_Test2: String; const w_Test3: Boolean); overload;
begin
  MessageDlg('TestB-B', mtInformation, [mbOk], 0);
end;

-------------  Add the Button click code ----------------

procedure TForm12.Button1Click(Sender: TObject);
var
  t_Func: TTestFunc;
begin
  Test('abc', nil);  //This is OK

  TestB('abc', nil, 'def'); //This is not

  TestB('abc', nil, 'def', 'ghi'); //This is not

  t_Func := nil;

  Test('abc', t_Func);  //This is OK

  TestB('abc', t_Func, 'def'); //This is OK

  TestB('abc', t_Func, 'def', 'ghi'); //This is OK
end;

--------------- Build -------------------
Workarounds
None
Attachment
None
Comments

Pierre le Riche at 11/12/2006 12:27:56 PM -
I suspect that is because a TTestFunc is actually two pointers: "procedure... of object" consists of a code address as well as an object reference. This may be why the compiler gets confused - it is not a "simple" typecast when you provide "nil" as input.

Server Response from: ETNACODE01