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
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
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.
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.
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.ModalResul t:=mrNone;
But believe that this not good solution. You have to find the reason.
ShowMessage('fgdfgdfg'); //your error message.
AddNewClassForm.ModalResul
ASKER
The call from form 1 to display the AddNewClassForm is from a button click as follows:
Add_New_Subject_Form.ShowM odal;
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.SubjectI D.Text := AddRecNum.Text;
Maintennance_Form.DBLookup Combobox1. SetText(Ad dFaculty.t ext);
Maintennance_Form.Subject_ Name.text := AddSubjectName.text;
Maintennance_Form.Subject_ AcaLvl.tex t := SelectYearCB.Text;
Datamodule1.SubjectSource. DataSet.Po st;
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
Add_New_Subject_Form.ShowM
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.SubjectI
Maintennance_Form.DBLookup
Maintennance_Form.Subject_
Maintennance_Form.Subject_
Datamodule1.SubjectSource.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i agree with rfwoolf.
You are closing your form with 'CLOSE' function.
So the model result of your Submit button must mrNone.
You are closing your form with 'CLOSE' function.
So the model result of your Submit button must mrNone.
A showMessage call has nothing to do with forms, so you must be doing something else as well.