Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Language/Overloading/Method    [ Add a report in this area ]  
Report #:  22593   Status: Closed
Overloaded method incorrectly reported as 'declared but never used'
Project:  Delphi Build #:  10.0.2166.28377
Version:    10.0 Submitted By:   Colin Ashworth
Report Type:  Minor failure / Design problem Date Reported:  12/20/2005 12:09:58 PM
Severity:    Commonly encountered problem Last Updated: 4/15/2014 6:50:39 PM
Platform:    All platforms Internal Tracking #:   8192
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
4.50 out of 5
Total Votes: None
Description
Overloaded method incorrectly reported as 'declared but never used'
Steps to Reproduce:
I created a streaming system to run alongside the TFiler mechanism. Therefore had overloaded methods called ReadData (TReaderProc) and ReadData (TMyReaderProc). This works fine in all previous versions of Delphi, however Delphi 2006 reports one of the overloaded methods as 'declared but never used'. This is an incorrect warning.

Have created a small test harness which illustrates the problem and the warning message using a very simple but representative scenario. This code results in a compiler warning...

[Pascal Hint] Unit4.pas(18): H2219 Private symbol 'MaxNum' declared but never used

(JJS See the attached app)

unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Math;

type
  TIntegerProc = function(Value1, Value2: Integer): Integer of object;
  TInt64Proc = function(Value1, Value2: Int64): Int64 of object;

  TForm4 = class(TForm)
  private
    { Private declarations }
    Val1, Val2: String;
    function MaxNum(Val1, Val2: Integer): Integer; overload;
    function MaxNum(Val1, Val2: Int64): Int64; overload;
  public
    { Public declarations }
    procedure RecordBiggestInteger(var ValStr: String; IntegerProc: TIntegerProc);
    procedure RecordBiggestInt64(var ValStr: String; Int64Proc: TInt64Proc);
    procedure RecordBiggestNumbers;
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

function TForm4.MaxNum(Val1, Val2: Integer): Integer;
begin
  result := Max(Val1, Val2);
end;

function TForm4.MaxNum(Val1, Val2: Int64): Int64;
begin
  result := Max(Val1, Val2);
end;

procedure TForm4.RecordBiggestInteger(var ValStr: String; IntegerProc: TIntegerProc);
begin
  ValStr := IntToStr(IntegerProc(58, 59));
end;

procedure TForm4.RecordBiggestInt64(var ValStr: String; Int64Proc: TInt64Proc);
begin
  ValStr := IntToStr(Int64Proc(60, 61));
end;

procedure TForm4.RecordBiggestNumbers;
begin
  RecordBiggestInteger(Val1, MaxNum);
  RecordBiggestInt64(Val2, MaxNum);
end;

end.
Workarounds
Declare the overloaded functions as protected rather than private.
Attachment
None
Comments

None

Server Response from: ETNACODE01