[fpc-pascal] Caller agnostic procedure variables

Sven Barth pascaldragon at googlemail.com
Tue Feb 15 20:46:23 CET 2022


Am 15.02.2022 um 15:05 schrieb Ryan Joseph via fpc-pascal:
>
>> On Feb 15, 2022, at 8:26 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> It's relatively "easy" to implement assigning a nested function to function references. However assigning a nested function variable to a function reference is much harder.
>> Assigning a function reference to a nested function variable is hard as well.
>>
> I'm getting lost with the terms now I think. If your function takes a function reference parameter and you assign it a nested function  pointer, this is difficult? I believe this was Michaels request in that code snippet.

=== code excerpt begin ===

// function/procedure/routine
function Foobar: LongInt; forward;

// function/procedure/routine variable
type
   TFoobarFunc = function: LongInt;

// method
   TFoo = class
     function Foobar: LongInt;
   end;

// method variable
   TFoobarMethod = function: LongInt of object;

// function/procedure/routine reference
   TFoobarFuncRef = reference to function: LongInt;

function Foobar: LongInt;

   // nested function/procedure/routine
   function FoobarSub: LongInt;
   begin
   end;

// nested function/procedure/routine variable
type
   TFoobarNested = function: LongInt is nested;

var
    f: TFoobarFuncRef;
begin
   // anonymous function/procedure/routine
   f := function: LongInt
         begin
         end;
end;

=== code excerpt end ===

Regards,
Sven


More information about the fpc-pascal mailing list