2

我有这行代码

    GAMBAR;
    SETBKCOLOR(15);
    BINTANG(17,0,23,12,23,12,36,12,0,12,13,12,36,12,26,21,26,21,29,34,29,34,18,27,18,27,7,34,7,34,10,21,10,21,0,12,0,12,13,12,13,12,17,0,2);
    READLN;
    FOR I:= 1 TO 20 DO
    BEGIN
        SKALA(17,0,23,12,23,12,36,12,0,12,13,12,36,12,26,21,26,21,29,34,29,34,18,27,18,27,7,34,7,34,10,21,10,21,0,12,0,12,13,12,13,12,17,0,2,I,I,XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        BINTANG(XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        DELAY(500);
    END;
    READLN;
    CLOSEGRAPH;
END.

但是 Turbo Pascal 给出错误“行长”

所以我试着这样做

    GAMBAR;
    SETBKCOLOR(15);
    BINTANG(17,0,23,12,23,12,36,12,0,12,13,12,36,
        12,26,21,26,21,29,34,29,34,18,27,18,27,7,
        34,7,34,10,21,10,21,0,12,0,12,13,12,13,12,17,0,2);
    READLN;
    FOR I:= 1 TO 20 DO
    BEGIN
        SKALA(17,0,23,12,23,12,36,12,0,12,13,12,36,12,26,21,26,21,29,
        34,29,34,18,27,18,27,7,34,7,34,10,21,10,21,0,12,0
        ,12,13,12,13,12,17,0,2,I,I,XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        BINTANG(XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        DELAY(500);
    END;
    READLN;
    CLOSEGRAPH;
END.

但是turbo Pascal给出了错误89:“)”预期。

我在谷歌上搜索了这个,但我一无所获。

那么,如何在 turbo pascal 中解决此代码?

此完整视图代码:

VAR GD,GM,XA,YA,XB,YB,W,I:INTEGER;
PROCEDURE GAMBAR;
BEGIN
    GD:=VGA;
    GM:=VGAHI;
    INITGRAPH(GD,GM,'D:\TP\BGI');
END;
PROCEDURE BINTANG(X0,Y0,X1,Y1,X2,Y2,X3,Y3,X4,Y4,X5,X6,X7,X8,X9,C:INTEGER);
BEGIN
    SETCOLOR(C);
    LINE(X0,Y0,X1,Y1);
    LINE(X1,Y1,X2,Y1);
    LINE(X2,Y1,X3,Y2);
    LINE(X3,Y2,X4,Y3);
    LINE(X4,Y3,X5,Y4);
    LINE(X5,Y4,X6,Y3);
    LINE(X6,Y3,X7,Y2);
    LINE(X7,Y2,X8,Y1);
    LINE(X8,Y1,X9,Y1);
    LINE(X9,Y1,X0,Y0);
END;
PROCEDURE SKALA(X0,Y0,X1,Y1,X2,Y2,X3,Y3,X4,Y4,X5,X6,X7,X8,X9,C,SX,SY:INTEGER;
    VAR XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W:INTEGER);
BEGIN   
    XA:=X0*SX;
    YA:=Y0*SY;
    XB:=X1*SX;
    YB:=Y1*SY;
    XC:=X2*SX;
    YC:=Y2*SY;
    XD:=X3*SY;
    YD:=Y3*SY;
    XE:=X4*SY;
    YE:=Y4*SY;
    XF:=X5*SY;
    XG:=X6*SY;
    XH:=X7*SY;
    XI:=X8*SY;
    XJ:=X9*SY;
    W:=C+2;
END;
{PROGRAM UTAMA}
BEGIN   
    GAMBAR;
    SETBKCOLOR(15);
    BINTANG(17,0,23,12,23,12,36,12,0,12,13,12,36,12,26,21,26,21,29,34,29,34,18,27,18,27,7,34,7,34,10,21,10,21,0,12,0,12,13,12,13,12,17,0,2);
    READLN;
    FOR I:= 1 TO 20 DO
    BEGIN
        SKALA(17,0,23,12,23,12,36,12,0,12,13,12,36,12,26,21,26,21,29,34,29,34,18,27,18,27,7,34,7,34,10,21,10,21,0,12,0,12,13,12,13,12,17,0,2,I,I,XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        BINTANG(XA,YA,XB,YB,XC,YC,XD,YD,XE,YE,XF,XG,XH,XI,XJ,W);
        DELAY(500);
    END;
    READLN;
    CLOSEGRAPH;
END.

感谢...

4

1 回答 1

2

过程中的参数数量必须在过程调用中匹配。该BINTANG()过程有 16 个参数,但在第一次调用中您传递了 45 个参数,这就是编译器抱怨的原因。第二次调用是正确的。

另请注意,调用中的参数数量不匹配SKALA()


关于 Turbo Pascal 中的最大程序行长度。它是 127。如果一行比这长,您将不得不拆分该行以匹配该限制。


如果您想将不同数量的 (X,Y) 对传递给画线过程,请学习如何使用DrawPoly(NumPoints: word; var PolyPoints).

例子 :

const 
  Triangle : array[1..4] of PointType =
    ((x:  50; y: 100),
     (x: 100; y: 100),
     (x: 150; y: 150),
     (x:  50; y: 100));
...
DrawPoly(SizeOf(Triangle) div SizeOf(PointType),Triangle); 

PointType是在 Graph 单元中声明的预定义类型。这将需要一些工作,但这是结构化编程的一个步骤。

于 2021-11-11T06:51:45.787 回答