Fancy Dialogs
Volume Number: 7
Issue Number: 6
Column Tag: MacOOPs!
Fancy Modal Dialogs 
By Thomas Engel, Loma Linda, CA
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
[Thomas Engel is a practicing anesthesiologist. He has been writing computer
simulations in physics, biology and physiology since 1975 and programming the
Macintosh since 1986.]
Most Macintosh programs use modal dialogs to convey information and get user
input. Whenever you pick an About, Open, Save As, Page Setup or Print menu
item you see a modal dialog. Error alerts and status messages are also forms of modal
dialogs. The Dialog Manager handles events for each dialog separately from the
application’s main event loop. Because the events are handled separately, the
programmer must duplicate event loop code or rely on the Dialog Manager’s default
behavior. Dialogs also have several unique features that require special consideration.
The Dialog Manager’s default behavior is not complete and does not provide many
standard Macintosh user interface features or subtle nuances. Many applications do not
provide these either. Although printer drivers and Standard File take care of most
details for their dialogs, you are on your own for any others. Object-oriented
programming can provide these features in a consistent way, with a minimum of
programming effort.
This article discusses some fine points of programming modal dialogs for the
Macintosh and presents a complete modal dialog class, subclasses and resources for six
useful dialogs and a short program to demonstrate each dialog. The dialog class is
written in Object Pascal with THINK Pascal 3.0, and should be portable to other
environments.
Dialog Basics
A dialog is a specialized window managed by the Dialog Manager. A dialog is
accessed by a DialogPtr like a window is accessed with a WindowPtr. The corresponding
DialogPeek is a pointer to a DialogRecord. To access the DialogRecord fields, typecast the
DialogPtr variable to a DialogPeek like this:
{1}
var
toolboxDialog: DialogPtr;
editItem: Integer;