I am creating one subForm from Main form on button click event of Main Form.Now On subForm I have added one button named ‘OK’.ModalResult property of Button set to mrOK. On Ok button click i want to peform some validations. If there is some error i want to show it on subform and should focus on the error filed of SubForm. But I am able to show error message and after error msg displayed Subform closes and main form will be displayed. Below is part of code. Plz help me.
result:= frmAddField.showModal= mrOK; // subForm
procedure TfrmAddField.btnOKClick(Sender:TObject);
begin
if edit1.text = '' then
begin
MessageDlg('Error',mtWarning,[mbOK],0);
edit1.setfocus;
break;
end;
// to be continued
end;
Breakis not what you want here. UseExitif you want to leave the current function or procedure. Also make sure that you only set the modal result if you want the form to close, in your example: