COMPILER 系统句柄

COMPILER 系统句柄让你看看有关最近编译的信息。

假设 ok-program.p 是一个没有任何错误或警告的程序:

COMPILE ok-program.p SAVE NO-ERROR.

DEFINE VARIABLE iError AS INTEGER     NO-UNDO.

MESSAGE  
    "Errors: "   COMPILER:ERROR SKIP
    "Warnings: " COMPILER:WARNING SKIP
    "Messages: " COMPILER:NUM-MESSAGES
    VIEW-AS ALERT-BOX INFORMATION.

这将促成:

StackOverflow 文档

使用警告编译程序:

/* program-with-warning.p */
DEFINE VARIABLE c AS CHARACTER   NO-UNDO.
DEFINE VARIABLE i AS INTEGER     NO-UNDO.

c = "hello".
DISPLAY c.
//This RETURN makes the program exit here and the code below unreachable.
RETURN.

IF TRUE THEN DO:
    i = 10. 
END.

编译程序:

COMPILE program-with-warning.p SAVE.

DEFINE VARIABLE iError AS INTEGER     NO-UNDO.

MESSAGE  
    "Errors: "   COMPILER:ERROR SKIP
    "Warnings: " COMPILER:WARNING SKIP
    "Messages: " COMPILER:NUM-MESSAGES
    VIEW-AS ALERT-BOX INFORMATION.

DO iError = 1 TO COMPILER:NUM-MESSAGES:
    DISPLAY 
        COMPILER:GET-FILE-NAME(iError)    LABEL "Filename" FORMAT "x(20)"
        COMPILER:GET-MESSAGE(iError)      LABEL "Message"  FORMAT "x(50)"
        COMPILER:GET-NUMBER(iError)       LABEL "Msg#"  
        COMPILER:GET-ERROR-COLUMN(iError) LABEL "Column"
        COMPILER:GET-ERROR-ROW(iError)    LABEL "Row"
            WITH FRAME fr1 SIDE-LABELS 1 COLUMNS.
END.

结果:

StackOverflow 文档

StackOverflow 文档

编译带有错误的程序

DEFINE VARIABLE c AS CHARACTER   NO-UNDO.
DEFINE VARIABLE i AS INTEGER     NO-UNDO.

c = "hello".
DISPLAY c.
//Casting should be required below...
IF TRUE THEN DO:
    i = c.
END.

编译程序:

//Use no-errors to supress any error messages from interrupting us.
COMPILE c:\temp\program-with-error.p SAVE NO-ERROR.

DEFINE VARIABLE iError AS INTEGER     NO-UNDO.

MESSAGE  
    "Errors: "   COMPILER:ERROR SKIP
    "Warnings: " COMPILER:WARNING SKIP
    "Messages: " COMPILER:NUM-MESSAGES
    VIEW-AS ALERT-BOX INFORMATION.

DO iError = 1 TO COMPILER:NUM-MESSAGES:
    DISPLAY 
        COMPILER:GET-FILE-NAME(iError)    LABEL "Filename" FORMAT "x(20)"
        COMPILER:GET-MESSAGE(iError)      LABEL "Message"  FORMAT "x(50)"
        COMPILER:GET-NUMBER(iError)       LABEL "Msg#"  
        COMPILER:GET-ERROR-COLUMN(iError) LABEL "Column"
        COMPILER:GET-ERROR-ROW(iError)    LABEL "Row"
            WITH FRAME fr1 SIDE-LABELS 1 COLUMNS 20 DOWN.

    DOWN WITH FRAME fr1.
END.

结果,每个错误几乎总是有两个错误。 无法理解之后是实际错误: StackOverflow 文档

StackOverflow 文档