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

EInvalidOperation on ShowModal() 3

Status
Not open for further replies.

ZoneVM

Programmer
Apr 7, 2005
30
US
I get an EInvalidOperation exception thrown when I call the showModal() method of one of my forms. The form is not in my auto-create list, i.e. I create this form using

f = new myForm(args....)

and then I call:

f->ShowModal();

Everything used to work fine until I added a TDateTimePicker object onto this form, from the Windows controls toolbar. After adding this, I get the above exception thrown with the message: "Cannot make a visible window modal". I have checked the Visible property of this form and it is NOT visible immediately before the ShowModal() call. Anyone seen this or have any tips? Thanks!
 
The error seems to indicate that you new form has already been created. Odd! I always do this when I create a new form.
Code:
    // Create and destroy new form
    try
    {
        NewForm = new TNewForm(args,..., this);
        NewForm->ShowModal();
    }
    __finally
    {
        delete NewForm;
        NewForm = 0;
    }

Just some thoughts, did you delete the *.obj files and other temp files and recompile? Did myForm somehow get put into the auto-create list? What happens when you remove the TDateTimePicker from the form?

James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
Thanks for the reply. I tried cleaning up the temp files to no avail. I tried rebooting the computer to no avail. I removed the TDateTimePicker... and still the same problem. I had thought it might be something to do with how I was using the picker... I read something about having to explicitly set the parent for this type of control. Anyway, I'm retracing all changes I've made to try and figure out what's up. The form is definitely not on the auto create list, but aside from that I'm just undoing seemingly unrelated changes to see if I can get to the root. Thanks!
 
from the builder help

I think the underlined part may apply

For components created programmatically, that is, not created in the form designer, call the constructor indirectly using the new keyword and pass in an owner component as the AOwner parameter. The owner disposes of the component when it is destroyed. If the component is not owned, then use delete when it needs to be destroyed.



Tip: When passing in this as the Owner parameter, consider what this references. If a component creates another component in one of its methods, then this refers to the first component and not the component being created, which is then owned by the first component.


perhaps

f = new myForm(Form1)
or
f = new myForm(Form1->Owner);




TC
 
Thanks everyone for the responses. I figured out what my problem was. Since I saw several other folks on the net having this same problem (but no solution that I found), I'll go ahead and post what happened in my case here:

I had inadvertently set the "Enabled" flag to false when I thought I was just greying out another component.

It turns out that the EInvalidOperation exception with message "Cannot make visible form modal" is raised when either the visible flag is true or the Enabled flag is false on the form that you want to make modal.

Hopefully this helps someone else with the same problem! Thanks again to all who helped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top