Example 3: DIALOG with SUBDIALOG

Form file "comment.per":
LAYOUT
GRID
{
[cmt                              ]
}
END
END
ATTRIBUTES
TEXTEDIT cmt = FORMONLY.the_comment, STRETCH=BOTH;
END
The module "comment.4gl":
PUBLIC TYPE cb_comment_event FUNCTION (event STRING)
PRIVATE DEFINE cb_ce cb_comment_event

PRIVATE DEFINE the_comment VARCHAR(200)

PUBLIC FUNCTION set_event_callback(f cb_comment_event)
    LET cb_ce = f
END FUNCTION

PUBLIC FUNCTION set_event_callback_2(f FUNCTION (event STRING))
    LET cb_ce = f
END FUNCTION

PUBLIC FUNCTION set_comment(s STRING)
    LET the_comment = s
END FUNCTION
    
PUBLIC FUNCTION get_comment()
    RETURN the_comment
END FUNCTION

DIALOG comment_input()
    INPUT BY NAME the_comment ATTRIBUTES(WITHOUT DEFAULTS)
        ON ACTION add_sep ATTRIBUTES(TEXT="Add sep")
           LET the_comment = the_comment || "\n---\n"
           CALL fgl_dialog_setcursor(LENGTH(the_comment)+1)
           IF cb_ce IS NOT NULL THEN
              CALL cb_ce("comment_changed")
           END IF 
        ON ACTION clr_cmt ATTRIBUTES(TEXT="Clear")
           LET the_comment = NULL
           IF cb_ce IS NOT NULL THEN
              CALL cb_ce("comment_changed")
           END IF
    END INPUT
END DIALOG
Form file "form1.per":
LAYOUT
VBOX
GRID
{
Id:   [f1        ]
Name: [f2                                        ]
}
END
FORM "comment"
END
END
ATTRIBUTES
EDIT f1 = FORMONLY.cust_id TYPE INTEGER;
EDIT f2 = FORMONLY.cust_name TYPE VARCHAR;
END
Program source code:
IMPORT FGL comment

MAIN
    DEFINE cust RECORD
            cust_id INTEGER,
            cust_name VARCHAR(50)
           END RECORD

    OPTIONS INPUT WRAP

    OPEN FORM f1 FROM "form1"
    DISPLAY FORM f1

    CALL comment.set_event_callback(FUNCTION event_callback)

    LET cust.cust_id = 199
    LET cust.cust_name = "Mike Patterson"
    CALL comment.set_comment("Some comment about this customer...")

    DIALOG ATTRIBUTES(FIELD ORDER FORM, UNBUFFERED)

        INPUT BY NAME cust.* ATTRIBUTES(WITHOUT DEFAULTS)
           ON ACTION check_exists ATTRIBUTES(TEXT="Check")
              MESSAGE CURRENT HOUR TO FRACTION(3), ": Check if customer exists"
        END INPUT

        SUBDIALOG comment_input

        ON ACTION close
           DISPLAY "Comment:", comment.get_comment()
           EXIT DIALOG

    END DIALOG

END MAIN

FUNCTION event_callback(event STRING)
    CASE event
      WHEN "comment_changed"
         MESSAGE CURRENT HOUR TO FRACTION(3), ": Comment changed..."
         DISPLAY "Comment: ", comment.get_comment()
    END CASE
END FUNCTION