I’m new in the Delphi programming scene and i have trouble calling a procedure in a procedure in my console application.
My simple application is for a item inventory running through a telnet server on windows.
I’m using a old thinkpad as my thinclient running linux and a telnet client.
Using Delphi XE I’ve ran into a chicken or the egg situation.
I get addscreen undeclared indentifier… it is declared but under mainscreen !!!
If i put addscreen procedure over the mainscreen one, any call to mainscreen in the addscreen procedure make me an error undeclared indentifier mainscreen!
In simple terms, how to make the procedure to be call everywhere in the program?
I’ve tried interface and implementation but its not valid in a console application program!
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, windows, messages, Console in 'Console.pas';
procedure mainscreen;
var
choice: string;
begin
clrscr;
writeln(' ------------------------------------------------------------------------------------------------------------------------------');
writeln(' | Inventory Management 0.1 ALPHA |');
writeln(' ------------------------------------------------------------------------------------------------------------------------------');
writeln('');
writeln('');
writeln('');
writeln('');
writeln('');
writeln(' Make a choice: Add(a), Remove(r), Edit(e), Backup Database(bd), Mass Add(ma), Mass Remove(mr)');
writeln('?:');
readln(choice);
if choice = 'a' then
addscreen
else
mainscreen;
end;
procedure addscreen;
var
choice: string;
begin
clrscr;
writeln(' ------------------------------------------------------------------------------------------------------------------------------');
writeln(' | Add an Item |');
writeln(' ------------------------------------------------------------------------------------------------------------------------------');
writeln('');
writeln('');
writeln('');
writeln(' Not yet ready!');
writeln(' Press any key to return to the main menu...');
readln(choice);
mainscreen;
end;
begin
mainscreen;
textbackground(black);
textcolor(lightgray);
ExitProcess(0);
end.
Thank you very much!
The compiler passes through the file from top to bottom. At the point where it needs to deal with the call to
addscreen, you have not yet declaredaddscreen.Since you have a circular reference (
addscreencallsmainscreenand vice versa) you need to break that with what is known as a forward reference. Add this line beforemainscreenSo the organisation of the code should look like this:
If you did not have a circular reference then you could simply reorder the procedures so that the
addscreenwas declared beforemainscreen.