Is there a native syntax to access the outer function Result variable from inner function in Delphi? -
consider:
function outerfunc: integer; function innerfunc: integer; begin // here i'd access outerfunc.result variable // both reading , writing value outerfunc.result := outerfunc.result + 12; end; begin end;
is there native syntax access outerfunc result variable inside innerfunc? or way pass parameter, in following?
function outerfunc: integer; function innerfunc(var outerresult: integer): integer; begin end; var i: integer; begin := innerfunc(result); end;
you can assign result functions assigning function name, original way in pascal:
function myfunc: integer; begin myfunc := 2; // equal following result := 2; end;
so in case can write
function outerfunc: integer; function innerfunc: integer; begin outerfunc := 12; end; begin end;
beware however, using function name in statement block anyware else on left side of assignment operator results in recursive call, , therefore different how predefined result
works.
in other words, can not access set value of outerfunc
within innerfunc
. need use e.g. local variable in outer scope defined before innerfunc
accessible innerfunc:
function outerfunc: integer; var outerresult: integer; function innerfunc: integer; begin outerresult := 0; outerresult := outerresult + 12; end; begin result := outerresult; end;
for more details refer function declarations
in the documentation.
Comments
Post a Comment