home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
OOPTUT34
/
DIALOG.TXT
< prev
next >
Wrap
Text File
|
1992-09-08
|
3KB
|
75 lines
DIALOG BOXES.
-------------
A dialog box is a special kind of window, with the type TDialog a
descendant of TWindow. It differs from a window in that it is grey, it is
neither resizable nor zoomable and it has no window number. Usually a
dialog box, when opened, is the only thing active and it is then said to be
the 'modal view'. If a dialog box object is 'inserted' into the desktop it
is non-modal, so to create a modal dialog box it must be 'executed' by
calling the DeskTop^.ExecView function. Programs TVGUID11.PAS and
TVGUID12.PAS illustrate non-modal and modal dialog boxes respectively.
A meaningful dialog box must have 'controls', such as an object of type
TButton, which acts like a status line item. It is a coloured region with
a text label, which will generate a command when clicked. Most dialog
boxes have at least two buttons, 'OK' and 'Cancel', which respectively
accept or cancel any changes made within the dialog box. The Dialogs unit
defines five standard dialog commands that can be bound to a TButton: cmOK,
cmCancel, cmYes, cmNo and cmDefault. Buttons, however, can be used to
generate commands specific to any application.
Creating a button requires four parameters for the Init constructor:
1. the region the button will cover (allowing for the shadow)
2. the text that will appear on the button
3. the command to be bound to the button
4. a button flag indicating the type of button (normal or default, which
responds to the ENTER key)
Program TVGUID13.PAS illustrates the statements used, including:
...
WITH Dialog^ DO
BEGIN
R.Assign(15, 10, 25, 12);
Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
...
END;
Control := DeskTop^.ExecView(Dialog);
...
To allow a user to choose among options, 'check boxes' and 'radio buttons'
are also provided in dialog boxes. Check boxes allow multiple selection,
whereas radio buttons allow one only choice. They are both descendants of
the object type TCluster. Many of the dialog boxes displayed by the
Options menu in the Turbo Pascal IDE feature this kind of cluster control.
The code for CheckBoxes includes:
B := New(PCheckBoxes, Init(R, NewSItem...
where the NewSItem function is in DIALOG.TPU, is shown on page 360 of the
Guide and returns a type PSItem, a pointer to a record type TSItem,
required by the constructor Init, inherited from TCluster (p 218).
The controls can be labelled using another control called the TLabel, which
can be inserted, allocated and initialized with the code:
Insert(New(PLabel, Init(R, 'LabelName', B)));
Full details of labelled controls are given on page 55 of the Guide and are
illustrated in program TVGUID14.PAS.
An 'input line' for editing string input can also be added to a dialog box.
TInputLine is the object type used, with the methods SetData and GetData
used to copy data to and from a view. See pages 55-59 of the Guide for
details and programs TVGUID15.PAS and TVGUID16.PAS for illustrations.
Standard dialog boxes are contained in the StdDlg unit (p 62).
DIALOG.WR1
DIALOG.TXT
22.3.91