[fpc-pascal] Delphi's anonymous functions in Free Pascal

Alexander Shishkin alexvins at mail.ru
Wed Oct 19 11:14:34 CEST 2011


19.10.2011 12:16, Sven Barth пишет:

> E.g.
>
> TIntegerFunc = reference to function: Integer;
>
> procedure SomeOtherProc(aFunc: TIntegerFunc);
> ...
>
> procedure Foo;
> var
> x: Integer;
> begin
> x := 42;
> SomeOtherProc(function: Integer; begin Result := x; end;);
> end;
>
> I haven't tested that, but from the description that should work.
>
> The FPC equivalent should be (not tested as well):
>
> type
> TIntegerFunc = function: Integer is nested;
>
> procedure SomeOtherProc(aFunc: TIntegerFunc);
> ...
>
> procedure Foo;
> var
> x: Integer;
>
> function ReturnX: Integer;
> begin
> Result := x;
> end;
>
> begin
> x := 42;
> SomeOtherProc(@ReturnX);
> end;
>
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>

But _real_ functional equivalent of Delphi's function reference if 
COM-interface based functor.
F.e.
"TMyFuction = reference to function: Integer; "
and
"IMyFunction = interface
     function Invoke:Integer;
end;"







More information about the fpc-pascal mailing list