Search code examples
functiondelphigenericsparameter-passing

TFunc<T> - is there any way to pass input parameter modificators?


I need to pass a function as a parameter like this:

procedure SomeProc(AParameter: TFunc<Integer, Integer>);

When I have this function...

function DoSomething(AInput: Integer): Integer;
...
SomeProc(DoSomething);
...

...the Delphi programming code works. But with parameter modifications like const, var, or default values like...

function DoSomething(const AInput: Integer = 0): Integer;

...compiler returns an error of mismatch parameter list.

Is there any way to pass parameter modificators, or avoid this error?

Many thanks for your suggestions.


Solution

  • Is there any way to pass parameter modificators, or avoid this error?

    No. The function you supply to SomeProc must have a signature that matches TFunc<Integer, Integer>.