Link to home
Start Free TrialLog in
Avatar of elschott
elschott

asked on

Dispaly modal form and showmessage error

I have two forms in an app, one which I will call the main form and a second form which is opened as a result of a button click that is called via the following piece of code

AddNewClassForm.ShowModal;

While the second form is displayed if I try to send an error via the showmessage routine, when the user clears the message the second form is closed also any idea how to bypass
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you show us your code please.
A showMessage call has nothing to do with forms, so you must be doing something else as well.
The answer might lie in the help file on Showmodal (See the "Note" below)

Use ShowModal to show a form as a modal form. A modal form is one where the application can't continue to run until the form is closed. Thus, ShowModal does not return until the form closes. When the form closes, it returns the value of the ModalResult property.
 
To close a modal form, set its ModalResult property to a nonzero value.
 Note:
 If the form contains buttons with a ModalResult property set to a value other than mrNone, the form automatically closes when the user clicks one of those buttons and returns the ModalResult value as the return value of ShowModal.
Avatar of dinilud
Can you explain more.






can you please show some code like mikelittlewood requested?
i think below solution will work for you.
But believe that this not good solution. You have to find the reason.



ShowMessage('fgdfgdfg'); //your error message.
AddNewClassForm.ModalResult:=mrNone;
Avatar of elschott
elschott

ASKER

The call from form 1 to display the AddNewClassForm is from a button click as follows:

Add_New_Subject_Form.ShowModal;

The Add New Subject Form basically has 4 fields and two buttons a submit and a cancel. I want to check if the user presses the submit button that all fields have values entered, if not show an error and return to the form, if the form is completed correctly the database record is appended to the dataset and the user is returned ot the original form here is the submit code I hope it helps

begin
  If (AddFaculty.Text = '') or (AddSubjectName.Text = '') then
    begin
      ShowMessage('All form fields are mandatory. Please complete form to add new subject');
    end
  else
    begin
      Maintennance_Form.SubjectID.Text := AddRecNum.Text;
      Maintennance_Form.DBLookupCombobox1.SetText(AddFaculty.text);
      Maintennance_Form.Subject_Name.text := AddSubjectName.text;
      Maintennance_Form.Subject_AcaLvl.text := SelectYearCB.Text;
      Datamodule1.SubjectSource.DataSet.Post;
      Close;
    end;  
end;

I took out the dataset.post and close lines and put another showmessage in there, which should show the message and then return to the form but when this show message is displayed it still closes the add new subject form, which made me think it had something to do with showmessage and showmodal

Thanks

Jake
ASKER CERTIFIED SOLUTION
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i agree with  rfwoolf.
You are closing your form with 'CLOSE' function.
So the model result of your Submit button must mrNone.