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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot make a visible window modal

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have a program that calls one of three Secondary Forms. Form_XXXX.ShowModal, from the Main Form. The Secondary Forms each have a Close Button that calls Close. One of the Secondary Forms returns to the Main Form. The other two do not with the following message “Cannot make a visible window modal.”
What is my problem and what is the solution? I have this problem frequently in several programs.
 
Not completely sure how you have your forms setup, but maybe this will solve the problem. I'm assuming you are not creating an MDI application...

From your Project menu select options, go to the forms tab and make your three secondary forms available, but not auto-created. They need to be listed in the right list box, your main form on the left list box.

add the units of each of the modal forms to the uses clause of your main form.

To open the secondary forms (only one open at a time)
Code:
var
   Child_Form:  TForm_XXXX; 
begin
   Child_Form := TForm_XXXX.Create(Application);
   if Child_Form.ShowModal = mrYes then 
      Caption := 'You Pressed Yes'
      //Do appropriate processing for positive return value
   else
      Caption := 'You Pressed No';
      //Do appropriate processing for negative return value
end;

Now on your modal forms, put two buttons on it, One with 'Yes' One with 'No' Captions, DELETE any code already associated with the button - as in Close; and then (while the button is selected) go to the object inspector and select the property ModalResult select mrYes for the Yes button and select mrNo for the No button (obviously you can select any from the list, not just Yes and No. But you'll need to change the code above from mrYes to the one you selected)

And last, make sure you set the modal form's visible property to FALSE...

end;
 
You can not show a form modally when the Visible property is set to true. Set it to false (in design or otherwise) before you call ShowModal.

(the error message is quite literal)

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top