If you want to use a user defined dialog box in a program you must first create the dialog box using the Resource Workshop. This is required, because the first step in creating the class that is maintains the dialog box is specifying the ID of the dialog box. For a description of the tools used in creating dialog boxes click here.
Once you have created your dialog box, you must create a class for it. Use class expert to create the new class.
Now that you have your class, you may use ClassExpert to create handers for various dialog features when you create instance variables. Instance variables are used to store data or actions entered by the user. Some of the common actions that are recorded along with the type of instance variable are:
| Enter Text | Text Box uses TEdit type of variable | It is important to select the correct type of interface for the your project. |
| Select from a List | ListBox uses a TListBox for a variable | |
| Select one item out of a fixed list | Radio Buttons use the type TRadioButton | |
| Select more than one item for a fixed list | Check Boxes use the type TCheckBox |
Instance variables should be initialized in the SetupWindow function.
We are used to using the ok and cancel button, but you can also add your own buttons to a dialog box using the button tool. Once you have a button, you can associate a function with the action of clicking.
Transfering data from the dialog box to the function calling the dialog box is done using a transfer buffer. Transfer buffers are structures that are automatically created by ClassExpert when you create instances of control structures. You could use the static variable also created by ClassExpert, but it is easier to create local transfer buffers and pass them to the constructor for your dialog box class.
The normal way to use dialog boxes is to create temporary variables using a constructor call. If your dialog box class is MyDialog and your transfer buffer is tb, calls take the form:
if (MyDialog(&tb,this).Execute() == IDOK)
{ // do the things required here
}
// not IDOK indicates the user cancelled operation. No action required usually.