2

The Free Pascal 2.6.2 compiler (using Delphi mode) complained about

program project16416258;

{$mode Delphi}

uses
  Classes;

type
  TFPCTestThread = class(TThread)
  public
    constructor Create(CreateSuspended: Boolean);
  end;

constructor TFPCTestThread.Create(CreateSuspended: Boolean);
begin
  inherited;
end;

begin
end.

with this error message:

ThroughputTestUnit.pas(82,19) Error: Wrong number of parameters
specified for call to "Create" Hint: Found declaration: constructor
TThread.Create(Boolean,const LongWord="4194304");

I fixed it using

  inherited Create (CreateSuspended);  

It seems to be caused by a change in 2.6.2, TThread has a constructor declaration with an optional second argument now:

 constructor Create(CreateSuspended: Boolean;
                    const StackSize: SizeUInt = DefaultStackSize);   
mjn
  • 36,362
  • 28
  • 176
  • 378
  • 1
    show the *declaration* of ur constructor TThroughputThread.Create: is it marked with `override`? `overload`? `c:\codetyphon\fpcsrc\rtl\objpas\classes\classesh.inc` really has TThread constructor with two parameters and they are fine to change their RTL as they see fit. What maybe is a bug is why your constructor `TThroughputThread.Create` declaration (not body) even compiled? – Arioch 'The May 07 '13 at 10:30
  • And this did not gave you warnings that is masks the "Create" method of base class? are constructors special case, that they do not require explicit marking with `reintroduce`/`overload`/`override` ? – Arioch 'The May 07 '13 at 11:24
  • 1
    @Arioch'The nope, at least in Lazarus 1.0.8 I see no warning (hints and warnings are enabled) – mjn May 07 '13 at 11:45
  • 1
    @Arioch, that warning generally only applies to virtual methods. That constructor isn't virtual, so there's no warning. The TObject constructor isn't virtual, either, which is why you've also never seen a warning when adding a new constructor to any direct TObject descendant. – Rob Kennedy May 07 '13 at 12:24

1 Answers1

3

inherited; calls base class constructor Create(CreateSuspended: Boolean). Since base class has no constructor which takes one boolean argument, you've got your error.

  • The second argument in the constructor is optional so this could be a matching signature. However I understand that calling the inherited constructor just by 'inherited;' is not the same as calling inherited Create(CreateSuspended). – mjn May 07 '13 at 11:05
  • That's right, Mjn. It's not just syntactic sugar to let you type less. It has a specific and distinct meaning, to call the inherited version of the current method with the current parameters. There is no inherited version of your current method, though. That's a breaking change in FPC's library. – Rob Kennedy May 07 '13 at 12:26