[Solved] Variable access when using a function from within a function lazarus / 21-General ---------------------------------------------------------------------- loaded · 2021-07-06 16:09 Hi All, When I run the sample code below Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function FvMain():integer;  function FChild():integer;  begin  result:=i*5;  end;vari:integer=10;beginresult:=FChild;end; Error: Identifier not found "i" I get an error. When using a function from within a function; How can I access main function variables? ---------------------------------------------------------------------- JuhaManninen · 2021-07-06 16:16 Define them above function FChild(). ---------------------------------------------------------------------- loaded · 2021-07-06 16:19 Thank you JuhaManninen for the reply. I can do as you said but; I need to use the inner function multiple times. If I can reach the main function content, my work will be much easier. ---------------------------------------------------------------------- JuhaManninen · 2021-07-06 16:29 Yes you can call the inner function multiple times and use the variables every time. No problem. What does not work? ---------------------------------------------------------------------- loaded · 2021-07-06 16:31 So what should I do if I want to use it in the following way ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function FMain():integer;  function FChild():integer;  begin  result:=i*5;  end;varf:integer;i:integer=10;begin   for f:=1 to 10 do i:=FChild;   result:=i;end; ---------------------------------------------------------------------- JuhaManninen · 2021-07-06 16:39 Quote from: loaded on July 06, 2021, 06:31:15 pmSo what should I do if I want to use it in the following way ? Again, define the variable above function FChild(). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function FMain():integer;var  i:integer=10;   function FChild():integer;  begin    result:=i*5;  end; var  f:integer;begin  for f:=1 to 10 do  i:=FChild;  result:=i;end; ---------------------------------------------------------------------- loaded · 2021-07-06 16:43 I cant believe; it shouldn't be this easy. I wouldn't have thought of it for 40 years. Thank you very very very much JuhaManninen ---------------------------------------------------------------------- lucamar · 2021-07-06 16:51 Quote from: loaded on July 06, 2021, 06:43:20 pmI cant believe; it shouldn't be this easy. I wouldn't have thought of it for 40 years. Should be pretty obvious if you remember than in Pascal you have to declare anything before you can use it. Keep that in mind and you'll never have this problem again ---------------------------------------------------------------------- loaded · 2021-07-06 17:08 Thank you lucamar for your suggestion, yes you are right, unfortunately I had the misfortune to start programming with qbasic. I didn't even have to define variables there.