: :
This message was edited by zibadian at 2006-12-31 9:52:40
: : : : : ok hi....for the same program....if i want to put a footer at the bottom of each page displaying "please press X at any time to return to the main menu" and then of course.....when someone presses the X key...what is the code to call back the main menu procedure?
: : : : :
: : : : You can use GotoXY() to position the text cursor (see help files for more info on GotoXY()).
: : : : The easiest way to handle this is to use a boolean to which indicates that the user pressed the X. Then each procedure should periodically check that boolean and use Exit() to stop.
: : : : A much more efficient way of coding (and much more advanced) is to make your program event driven. This allows the program to call any code at any time.
: : : :
: : :
: : :
: : :
: : : wowo thanks...but can u provide code to do this?
: : : i am not very versed in programming as you realised
: : :
: : Here's the code to check the boolean:
: :
: : if HasUserTypedX then
: : Exit;
: :
: : Insert this line before each read()/readln() and in all loops in procedures, which are called by the main menu. To check if the user typed X, use this code:
: :
: : if UserInput = 'X' then
: : HasUserTypedX := true;
: :
: : In the main menu set the HasUserTypedX boolean back to false.
: : As you can see, it's not one piece of code, but several, which need to be inserted in several places of your current code.
: :
:
: hey Zibadian, could you tell me more about that event-driving? or atleast where can I find information and knowledge aboutt this stuff?
:
Basically event-driven applications are a very short loop, which checks for something to do. In pseudo code:
begin
repeat
if Event found then
HandleEvent
Do other processes
until end program
end
A working Pascal example is this:
uses
Crt;
var
ch: char;
i: integer;
s: string;
begin
i := 0;
s := '';
repeat
{ Other process: count to 100000 }
GotoXY(1, 1);
writeln(i);
if i > 100000 then
i := -1
else
inc(i);
{ Event: keyboard key press }
if KeyPressed then
begin
ch := ReadKey;
s := s + ch;
writeln(s);
end;
until ch = 'Q'; { Program end: SHIFT+Q }
end.
For more info on event-driven programming see this article:
http://en.wikipedia.org/wiki/Event-driven