The COMPILER
system handle let's you look at information regarding a recent compile.
Assuming ok-program.p
is a program without any errors or warning:
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.
This will procude:
Compiling a program with a warning:
/* 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.
Compiling the program:
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.
Result:
Compiling a program with an error
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.
Compiling the program:
//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.
Result, there's almost always two errors per error. "Could not understand" is followed by the actual error: