Dialog Box Components

Introduction

You will normally use a dialog box to collect or alter information. There are many components you may add to a dialog box to assist in collecting data. It is important to choose a component that is suited to the data you are collecting. This page will cover commonly used components from least restrictive to most restrictive.

Straight Text

If you want to collect text that has no restrictions on either form or content, you may use a TEditBox (pallet button ). You may label the box using either simple label or for a more professional look you can surround the text box with a groupbox. You may see a sample of this by clicking here. An example of using this type of text box is given in the payroll example add employee program.

Formated Text

When you want to make sure that data such as phone numbers and addresses, you should used the masked edit box .

Fixed Number of Predetermined Values

If you have a fixed number of predetermined types such as the types of employee in the payroll program, you may use radio buttons. Radio buttons contain their own text, so you do not need extra components to display the choices.

An easier way to construct a set of radio buttons is the Radio Group. When you create a RadioGroup, the Items property is the list of radio buttons that will appear in the group box. You need only type the caption for each radio button in the items (found in the Object Inspector). You may designate the number of columns in the columns property. Below you see the Object Inspector and the form with the RadioGroup described there.

The ItemIndex indicates which button is Checked, so you don't have to have a nested sequence of checks. Borland describes the ItemIndex use as follows:

ItemIndex holds the ordinal number of the selected radio button in the Items list. (The first button is 0.) The value of ItemIndex changes at runtime as the user selects radio buttons. If you want one of the buttons to appear selected when the application starts, assign that button to ItemIndex at design time; otherwise, leave ItemIndex set to the default value of -1, which means that no button is selected.

Fixed Number of Choices That May Change in Time

In a lab you are asked to create a dialog that will take reservations at a resort that has condos and boat slips. Other resorts may want to use this program and they might have boat rentals or bike rentals or cabin rentals. The easiest way to handle this is with a ComboBox. The combobox allows you to change the items listed either at compile or run time. It is possible to change the radio buttons at runtime or compile time, but because all buttons are visible, you have to redesign the dialog every time you change the number of buttons. The combobox stores the choices in a location (the items) where they are only seen when the user wants to make a choice. This means the dialog does not need to be redesigned when the choices change. The ItemIndex indicates the item chosen. The Text field is always visible, and should represent the default choice. Make sure that you set the ItemIndex to the default choice either at compile time (in the Object Inspector) or at runtime.