Pascal程序不显示完整输出

时间:2014-01-13 20:56:16

标签: menu scroll console output pascal

我的学校任务是用pascal创建一个类似菜单的程序,显示其他程序的代码。它逐行从文件中读取文本并将其打印到控制台。当它没有显示完整输出时,它工作正常。这是它显示的输出: http://postimg.org/image/3r4ua8poz/

当它运行时,它会逐行显示所有内容,但最后您只能看到适合控制台窗口的代码部分,而您无法向上滚动。谁能告诉我如何解决这个问题?这将是非常值得赞赏的。 这是实际代码:

    program pascalMenu  //ime na programata
{$mode objfpc};//OOP pascal ili neshto takova(zaduljitelno e)
uses sysutils,
 crt, graph;
Var choice : array[1..5] of string;//masiv, v sluchaq sadurja chas ot imenata na failovete
programFile : Text;//shte sudurja imeto na faila
userFile,line,number,filename : string;
i,j,value : integer;
c : char;
begin
        writeln('This program will open all of our previous tasks.');

        //pulnene na masiva
        for i := 1 to 5 do
        begin
                str(i,number);
                choice[i] := 'program' + number;
        end;
        j:=1;

        repeat
        writeln( 'Use the arrow keys to navigate, ENTER to open and ESC to close.');


        //pokazvane na elementite v masiva sled vsqka vrutka na cikula
        for i:= 1 to 5 do
           begin
              if i = j then
              begin
                //tva e za cveta
                 textcolor(red);
                 writeln(choice[i]);
                 textcolor(white);
                 continue;
              end;
              writeln(choice[i]);

           end;

        //beggining the menu loop

        c := readkey;//chetene na kopche rofl
        clrscr;// - chisti konzolata(optional)
        if ord(c) = 0 then
        c := readkey;
        value := ord(c);
        //options
        case value of
        72 :
                begin
                j:= j - 1;
                if j < 1 then j :=5;
                end;
        80:
                begin
                j:= j + 1;
                if j > 5 then j:= 1;
                end;
        13:
                begin
                str(j,number);
                filename := 'program' + number + '.txt';
                assignfile(programFile,filename);//prilaga imeto na faila na promenlivata
                //tva nz za kakvo e, obache sled 5-q opit reshi, che bez nego nemoje
                try
                reset(programFile);//otvarq faila za chetene

                repeat

                        readln(programFile, line);//chete 1 red ot faila v line
                        writeln(line);
                until (Eof(programFile));//eof - end of file
                closefile(programFile);//zaduljitelno!! bez nego ne mogat dase otvarqt 2/poveche faila
                                        //zaradi greshka v read/write dostupa
                except on E:EInOutError do begin
                writeln('The program could not read the file. Check the file''''s''name and directory.');end;
                end;

                writeln('Press any key to return to the main menu.');
                writeln('P.S. - This will erase the text');
                readln;
                clrscr;
                end;
        end;
        until value =27;


end.

1 个答案:

答案 0 :(得分:0)

使用单位Crt禁止滚动。不用它。

或者看一下FPC附带的“lister”演示,它会尝试一些相同的(光标移动以供选择和显示)