I'm trying to use an array of Integer
parameter inside an anonymous method passed as parameter to another function:
type
TAnonymousMethod = reference to procedure();
procedure SubTest(AMethod : TAnonymousMethod);
begin
AMethod();
end;
procedure Test(ACodes : array of Integer);
begin
SubTest(
procedure()
begin
ShowMessage(IntToStr(Length(ACodes)));
end
);
end;
On compiling it produces the following E2555 error:
[dcc32 Error] Unit1.pas(38): E2555 Cannot capture symbol 'ACodes'
I've tried to do the same thing using one only Integer
value and it compiled without errors.
procedure Test(ACode : Integer);
begin
SubTest(
procedure()
begin
ShowMessage(IntToStr(ACode));
end
);
end;
So the problem seems to be related to the open array parameters only.
Why does this happen and how could it be avoided?