Playing around with Berlin 10.1 and discovered what I almost feel is a compiler bug

Playing around with Berlin 10.1 and discovered what I almost feel is a compiler bug

unit Unit3;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
TTestClass = class
public
constructor Create(const aMessage: String);
procedure Proc(const aMessage: String);
function Func(const aMessage: String): Boolean;
end;

TForm3 = class(TForm)
procedure FormCreate(Sender: TObject);
private
fTest: TTestClass;
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation

{$R .dfm}

procedure TForm3.FormCreate(Sender: TObject);
begin
fTest := TTestClass.Create('Create Class');
fTest.Proc('Call proc');
fTest.Func('Call func');
end;

constructor TTestClass.Create
{ (const aMessage: String) This line can be commented out };
begin
ShowMessage(aMessage);
end;

procedure TTestClass.Proc
{ (const aMessage: String) This line can be commented out };
begin
ShowMessage(aMessage);
end;

function TTestClass.Func()
{ (const aMessage: String) This line cannot be commented out *}: Boolean;
begin
Result := True;
ShowMessage(aMessage);
end;

end.

I think it is an error to not have the same signature on class definition and implementation. But it works fine to leave that out. At least a hint!
Also tried the same with Delphi 2007 and the same behaviour.

Comments

  1. That is documented behavior (note the "can"): "In the heading of a defining declaration, the method name is always qualified with the name of the class to which it belongs. The heading can repeat the parameter list from the class declaration; if it does, the order, type, and names of the parameters must match exactly, and if the method is a function, the return value must match as well."

    ReplyDelete
  2. Uwe Raabe Ok, I wasn't aware of that. But I think 99% of all developers try to match them

    ReplyDelete
  3. This behavior has been around even before objects in Turbo pascal. The function or procedure in the implementation doesn't have to repeat the parameter list that is in the interface section.

    ReplyDelete
  4. And if you want to make an overload what happen?

    ReplyDelete
  5. Ivan Revelli This is also documented: "The implementation of an overloaded method must repeat the parameter list from the class declaration."

    ReplyDelete
  6. I don't understand why anybody would suspect a compiler bug without reading the documentation.

    http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Methods_(Delphi)

    Why do people not spend the time to read documentation?
    docwiki.embarcadero.com - Methods (Delphi) - RAD Studio

    ReplyDelete
  7. David Heffernan ops I really didn’t read that

    ReplyDelete
  8. "I wish it was a bug, but no, it's delphi."

    I want that on a t-shirt for my birthday!

    ReplyDelete

Post a Comment