PDA

View Full Version : [SOLVED] 2 procedures callind each other ... HOW ?



arthurprs
28-07-2007, 10:30 PM
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


uses

var

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

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

begin
end.

how solve ?

*Sorry my english :?

PS: thx for unlok it will

technomage
28-07-2007, 10:53 PM
you need what is called a forward declaration.


procedure y; forward;


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


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.


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.

arthurprs
29-07-2007, 12:18 AM
you need what is called a forward declaration.


procedure y; forward;


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


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.


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 ^^