Results 1 to 3 of 3

Thread: [SOLVED] 2 procedures callind each other ... HOW ?

  1. #1

    [SOLVED] 2 procedures callind each other ... HOW ?

    Hello i was converting my code from VCL/GDI to CONSOLE/SDL and i found a unusual problem,

    i have 2 procedures that calls the other one and this one call who called it, it looks some kind of circle but the procedure down can call procedure that is up but that ones can't call the one it's down :?

    looks like

    [pascal]
    uses

    var

    procedure x;
    begin
    if something then
    y(); // error here
    end;

    procedure y;
    begin
    if something then
    x();
    end;

    begin
    end.[/pascal]

    how solve ?

    *Sorry my english :?

    PS: thx for unlok it will
    From brazil (:

    Pascal pownz!

  2. #2

    [SOLVED] 2 procedures callind each other ... HOW ?

    you need what is called a forward declaration.

    [pascal]
    procedure y; forward;
    [/pascal]

    You don't get this kind of thing when using units because you declare the function in the interface sections and then put the code in the implementation section.

    When putting code in the main .dpr unit you don't tend to have an interface or implementation section just the uses and begin/end.

    Here is a sample project

    [pascal]
    program Project2;
    {$APPTYPE CONSOLE}
    uses Classes;

    var something: Boolean;

    procedure y; forward;

    procedure x;
    begin
    if something then
    y(); // error here
    end;

    procedure y;
    begin
    if something then
    x();
    end;

    begin
    end.
    [/pascal]

    But I would ask your self why you want x to call y and then y to call x, if you are not careful you could end up blowing the stack.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3

    [SOLVED] 2 procedures callind each other ... HOW ?

    Quote Originally Posted by technomage
    you need what is called a forward declaration.

    [pascal]
    procedure y; forward;
    [/pascal]

    You don't get this kind of thing when using units because you declare the function in the interface sections and then put the code in the implementation section.

    When putting code in the main .dpr unit you don't tend to have an interface or implementation section just the uses and begin/end.

    Here is a sample project

    [pascal]
    program Project2;
    {$APPTYPE CONSOLE}
    uses Classes;

    var something: Boolean;

    procedure y; forward;

    procedure x;
    begin
    if something then
    y(); // error here
    end;

    procedure y;
    begin
    if something then
    x();
    end;

    begin
    end.
    [/pascal]

    But I would ask your self why you want x to call y and then y to call x, if you are not careful you could end up blowing the stack.
    Mine sweeper game, when the guy cliks on a block that have 0 mines around ^^
    From brazil (:

    Pascal pownz!

Bookmarks

Posting Permissions

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