This error message is issued if you try to assign a local procedure to a procedure variable, or pass it as a procedural parameter.
This is illegal, because the local procedure could then be called even if the enclosing procedure is not active. This situation would cause the program to crash if the local procedure tried to access any variables of the enclosing procedure.
program Produce; var P: Procedure; procedure Outer; procedure Local; begin Writeln('Local is executing'); end; begin P := Local; (*<-- Error message here*) end; begin Outer; P; end.
The example tries to assign a local procedure to a procedure variable. This is illegal because it is unsafe at runtime.
program Solve; var P: Procedure; procedure NonLocal; begin Writeln('NonLocal is executing'); end; procedure Outer; begin P := NonLocal; end; begin Outer; P; end.
The solution is to move the local procedure out of the enclosing one.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!