Nesting procedures in SCAR

Discussion in 'Code Snippets and Tutorials' started by skeithman25, Apr 16, 2009.

  1. skeithman25

    skeithman25 Newbie

    Joined:
    Apr 14, 2009
    Messages:
    5
    Likes Received:
    0
    In other pascal languages I've used you can put procedures inside other procedures like this:


    Code (Text):
    1.  
    2. procedure outsideprocedure
    3.    var
    4.     oustidevar : integer;
    5.    procedure insideprocedure
    6.       var
    7.        insidevar : string;
    8.       begin
    9.        <insidecodehere>
    10.       end; //end inside procedure
    11.    begin
    12.     <outsidecodehere>
    13.    end; //end outside procedure
    14.  
    but in SCAR when I do this i get a message saying begin expected on the : "procedure insideprocedure" line. How can I nest succesfully?!
     
  2. jazzeh

    jazzeh Level I

    Joined:
    Jan 1, 2008
    Messages:
    144
    Likes Received:
    15
    Is it necessary to nest the procedures?

    Possible to just move the begin since originally the inside procedure wasn't inside the outside procedure?
    Code (Text):
    1.  
    2. procedure outsideprocedure
    3. var
    4.   oustidevar : integer;
    5. begin
    6.   procedure insideprocedure;
    7.   var
    8.     insidevar : string;
    9.   begin
    10.     <insidecodehere>
    11.   end; //end inside procedure
    12.   <outsidecodehere>
    13. end; //end outside procedure
    14.  
    or Can't you just call the inside procedure from outside procedure like :
    Code (Text):
    1.  
    2. procedure insideprocedure;
    3. var
    4.   insidevar : string;
    5. begin
    6.   <insidecodehere>
    7. end; //end inside procedure
    8.  
    9. procedure outsideprocedure;
    10. var
    11.   oustidevar : integer;
    12. begin
    13.   insideprocedure;
    14.   <outsidecodehere>
    15. end; //end outside procedure
    16.  
    I don't know the benefits of nesting procedures like that since you still have to call it for it to fire.
     
  3. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    the only thing you need to know about this is that the procedure you're calling MUST be before the caller.

    Code (Text):
    1. procedure IWasCalled
    2. begin
    3.   Blah Blah;
    4. end;
    5.  
    6. procedure IMCalling
    7. begin
    8.   IWasCalled;
    9. end;
     
  4. skeithman25

    skeithman25 Newbie

    Joined:
    Apr 14, 2009
    Messages:
    5
    Likes Received:
    0
    Thanks you guys, I have managed to make it work now.The reason I wanted it nested was so that it could use the variables of the outside procedure, but without making them global. I've rewritten my code so that this is less of a problem. Thanks!