Helper/function overloads

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Helper/function overloads

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Helper/function overloads

Michael Van Canneyt


On Wed, 10 Apr 2019, Ryan Joseph wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Helper/function overloads

Anthony Walter-3
In reply to this post by Ryan Joseph
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.                        

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal