After reading Embarcadero's documentation on procedural types & anonymous methods and David Heffernan's explanation on that matter, I still don't quite understand why the compiler forbids initializing a constant array of reference to function, as C_BAR in the example below.
program MyProgram;
{$APPTYPE CONSOLE}
{$R *.res}
type
TFoo = function: Integer;
TBar = reference to function: Integer;
function FooBar: Integer;
begin
Result := 42;
end;
const
// This works
C_FOO: array[0..0] of TFoo = (FooBar);
// These lines do not compile
// C_BAR: array[0..0] of TBar = (FooBar); // TBar incompatible with Integer
// C_BAR: array[0..0] of TBar = (@FooBar); // TBar incompatible with Pointer
var
Foo: array[0..0] of TFoo;
Bar: array[0..0] of TBar;
begin
Foo[0] := FooBar; // Foo[0] = MyProgram.FooBar
Bar[0] := FooBar; // Bar[0] = MyProgram$1$ActRec($1CC8CF0) as TBar
Foo[0] := C_FOO[0]; // Foo[0] = MyProgram.FooBar
Bar[0] := C_FOO[0]; // Bar[0] = MyProgram$1$ActRec($1CC8CF0) as TBar
end.
Using the debugger, I can see Bar[0] being equal to some address (I think?), which tells me something is happening behind my understanding...
So is it possible to initialize a constant array like C_BAR in my example? If yes, how to do it, and otherwise, why?