【问题标题】:Pascal program doesnt show the full outputPascal 程序不显示完整的输出
【发布时间】:2014-01-13 20:56:15
【问题描述】:

我的学校任务是使用 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.

【问题讨论】:

    标签: menu scroll console output pascal


    【解决方案1】:

    使用单位 Crt 禁止滚动。取消使用它。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多