[fpc-pascal] Callbacks as nested functions
Michael Van Canneyt
michael at freepascal.org
Mon Oct 23 15:38:50 CEST 2017
On Mon, 23 Oct 2017, Ryan Joseph wrote:
>
>
>> On Oct 23, 2017, at 4:56 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> What exactly are you trying? If the nested function accesses its outer scope then it definitely won't work. For that you'd need to wait for anonymous function support (which are planned - at least a far as I'm concerned - to also support nested functions).
>>
>
> I cast DoThis to the type but the arguments are not correct not and a does not equal 0.
>
> type
> TCallback = procedure (a: integer);
>
> procedure DoCallback;
> procedure DoThis(a: integer);
> begin
> writeln(a);
> end;
> var
> callback: TCallback;
> begin
> callback := TCallback(@DoThis);
> callback(100);
> end;
You can't use a local procedure for this, as far as I know.
Michael.
More information about the fpc-pascal
mailing list