Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modal or Non-Modal dialogs? 1

Status
Not open for further replies.

clifff

Programmer
Mar 22, 2002
20
MD
Hi! How to specify in Builder that a form(dialog) will be Modal or Non modal?

thanks, clifff.
 
When you want to show the form, you use Form2->Show() [assuming that the form is called Form2]. Calling Form2->ShowModal() instead will show the dialog box modally. Set the ModalResult property of buttons on your form to something other than mrNone or set it's OnClick function to set Form2->ModalResult to other than mrNone. When the form's ModalResult changes to not mrNone, the form closes and ShowModal() returns the modal result, for example:

Code:
/* UNIT1.CPP */
#include "Unit2.h"

void __fastcall Form1::Button1Click(TOBject *Sender)
{
if (Form2->ShowModal() == mrOk) {
    // Do something (user clicked OK)
    }
}

/* UNIT2.CPP */
void __fastcall Form2::OkButtonClick(TObject *Sender)
{
ModalResult = mrOk;
}
void __fastcall Form2::CancelButtonClick(TObject *Sender)
{
ModalResult = mrCancel;
}

You can also experement with setting FormStyle to fsStayOnTop - this makes the form not modal, but always shows over other forms. [pc3]
In the end it will probably be the simplest, most obvious thing that I was doing wrong...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top