[fpc-pascal] Callbacks as nested functions
Ryan Joseph
ryan at thealchemistguild.com
Mon Oct 23 16:01:33 CEST 2017
> On Oct 23, 2017, at 8:55 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>
> program test1;
>
> {$mode objfpc}{$H+}
> {$ModeSwitch nestedprocvars}
>
> type
> TCallback = procedure (a: integer) is nested;
>
> procedure DoCallback;
> procedure DoThis(a: integer);
> begin
> writeln(a);
> end;
> var
> callback: TCallback;
> begin
> callback := @DoThis;
> callback(100);
> end;
>
> begin
> DoCallback;
> end.
>
> Keep in mind what Sven wrote. You cannot use "callback" outside of
> DoCallBack, because FPC does not yet support Delphi's "reference to".
Thanks, I never heard of nestedprocvars. Why isn’t that the default? If I have a callback I may have it be nested or not so I always want “is nested” on I guess.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list