How can I suppress to close the form when hitting the OK button? I have the following code:
void __fastcall TfrmTillegg_velg::btnOkClick(TObject *Sender)
{
if (exp1)
ShowMessage("Not allowed"); // Don't close form
else if (exp2)
ShowMessage("Not allowed"); // Don't close form
else
{
// Do something here
Close();
}
}
The project is written in Borland c++builder.
If you mean keeping the dialog created by
ShowMessageopen. then as far as I am aware, you cannot do this. The dialog displayed byShowMessagewill close whenever you click any of its buttons. If you want a popup dialog that will not close in this way, you will need to create a custom form yourself and control its behaviour according to your needs.Just in case your question is referring to your main form closing, then you do have an explicit call to
Close()within your button click event handler above that will cause your form to close whenever both of yourexp1andexp2conditions are false.