Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-04

Helper/function overloads

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Ryan Joseph

Is this a bug or intended behavior? I can call it like Test.DoThis but it seems like overloading should work.

{$mode objfpc}
program test;
type
  THelper = class helper for TObject
    procedure DoThis; overload;
  end;
procedure DoThis (param: string); overload;
begin
end;
procedure THelper.DoThis;
begin
  DoThis('string'); // <——— ERROR: Wrong number of parameters specified for call to "DoThis"
end;
begin
end.

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Ryan Joseph
Ryan Joseph wrote 21 lines
Is this a bug or intended behavior? I can call it like Test.DoThis but it seems like overloading should work. {$mode objfpc} program test; type THelper = class helper for TObject procedure DoThis; overload; end; procedure DoThis (param: string); overload; begin end; procedure THelper.DoThis; begin DoThis('string'); // <——— ERROR: Wrong number of parameters specified for call to "DoThis" end; begin end.

As far as I know, in a method "overload" only means it checks higher up the inheritance chain. Delphi gives the same error.

Michael.

Reply by email

Anthony Walter
to Ryan Joseph: Is this a bug or intended behavior? I can call it like Test.DoThis but it seems like…

I'm not sure if this is anything you're interested in but ...

You can qualify the of the procedure with the unit or program identifier.

program Test;
{$mode objfpc}
type
  THelper = class helper for TObject
    procedure DoThis;
  end;
procedure DoThis(Param: string);
begin
  WriteLn(Param);
end;
procedure THelper.DoThis;
begin
  Test.DoThis('Hello World');
end;
var
  Obj: TObject;
begin
  Obj := TObject.Create;
  try
    Obj.DoThis;
  finally
    Obj.Free;
  end;
end.

Reply by email