Results 1 to 7 of 7

Thread: Forward Question

  1. #1
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default Forward Question

    I've seen things like
    SCAR Code:
    Procedure TickleMyPickle; Forward;
    What is the forward used for?

  2. #2
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    It means that the function is declared somewhere further down the script. Normally you can only use functions that are above the current function, but sometimes you need one that's below it.

    SCAR Code:
    program New;

    procedure test;
    begin
      test2;
    end;

    procedure test2;
    begin
      WriteLn('hoi');
    end;

    begin
      test;
    end.

    Doesn't work, because test2 is beneath test.

    SCAR Code:
    program New;

    procedure test2; forward;

    procedure test;
    begin
      test2;
    end;

    procedure test2;
    begin
      WriteLn('hoi');
    end;

    begin
      test;
    end.

    works

  3. #3
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Example...
    SCAR Code:
    porgram ForwardExample;

    function Num3: string; forward;

    procedure Num1;
    begin
      WriteLn(Num3);
    end;

    function Num2: string;
    begin
      Result := 'Boo!...';
    end;

    function Num3: string;
    begin
      Result := Num2;
    end;

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  4. #4
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Thanks! I just found out that'll be extremely useful in my script!

  5. #5
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by DeSnob View Post
    Thanks! I just found out that'll be extremely useful in my script!
    Its good practice not to use it =) most of the time you can just rearrange procedures

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  6. #6
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    Its good practice not to use it =) most of the time you can just rearrange procedures
    Whats the downside of using it?
    There used to be something meaningful here.

  7. #7
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Increase of compiling time and it can be annoying to maintain both of the declarations, but it's not that bad to use it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •