User Created Modal Dialogs

Any form can be displayed using the ShowModal function, but in order to return the appropriate constant from your button handlers, you need to set the ModalResult to an integer value in each handler. If you have created your own ok button, you will want to set the ModalResult to ID_OK. The cancel button can return ID_CANCEL. A list of the normal constant integers can be found in the Borland help.

All you need to do in the appropriate handler is to add the assignment at the bottom of the handler code. When the ShowModal function see that the ModalResult is set it quites returning that result. The following are examples of a simple program in which panels were used in place of buttons for ok and cancel. The form looks like the following.

The code used with this dialog follows.

void __fastcall  TmyDialog::OkBtnClick(TObject *Sender)
{
       ModalResult =ID_OK;

}
//---------------------------------------------------------------------------


void __fastcall  TmyDialog::Panel1Click(TObject *Sender)
{
        ModalResult = ID_CANCEL;        
}
//---------------------------------------------------------------------------

For a complete copy of this program click here .