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.
這將促成:
使用警告編譯程式:
/* 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.
結果:
編譯帶有錯誤的程式
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.
結果,每個錯誤幾乎總是有兩個錯誤。 無法理解之後是實際錯誤: