4.1 An example

Before diving into the complexities we will illustrate normal usage through an example. The following Prolog predicate creates a dialog for entering information on an employee. The result, running on Windows-NT, is shown in figure 8.

ask_employee :-
        new(Dialog, dialog('Define employee')),
        send_list(Dialog, append, 
                  [ new(N1, text_item(first_name)),
                    new(N2, text_item(family_name)),
                    new(S,  new(S, menu(sex))),
                    new(A,  int_item(age, low := 18, high := 65)),
                    new(D,  menu(department, cycle)),
                    button(cancel, message(Dialog, destroy)),
                    button(enter, and(message(@prolog,
                                              assert_employee,
                                              N1?selection,
                                              N2?selection,
                                              S?selection,
                                              A?selection,
                                              D?selection),
                                      message(Dialog, destroy)))
                  ]),
        send_list(S, append, [male, female]),
        send_list(D, append, [research, development, marketing]),
        send(Dialog, default_button, enter),
        send(Dialog, open).

assert_employee(FirstName, FamilyName, Sex, Age, Depth) :-
        format('Adding ~w ~w ~w, age ~w, working at ~w~n',
               [ Sex, FirstName, FamilyName, Age, Depth]).

This example shows the layout capabilities of dialog and its dialog_item objects. Simply appending items will place items vertically and group buttons in rows. Labels are properly aligned. The enter button defines a call-back on the predicate assert_employee/5 using the values from the various controllers. Section 10.2 explains the use of message objects in detail.

Figure 8 : Enter employee