"Cannot make a visible Window modal"

Posted on 2009-04-13
Last Modified: 2012-05-06
I get the above error when running the code shown below. TfrmAddUser is NOT in the auto-create list. Its relevant properties are set as follows:

Visible: False
Enabled: True
FormStyle: fsNormal
WindowState: wsNormal

I am using Delphi 2006. I checked the existing Question:

... but nothing there seemed to make it work either. Any ideas, anyone?
procedure TfrmUserRoles.mAddUser;
  loAddUser: TfrmAddUser;
  lsUserID: string;
  loAddUser := TfrmAddUser.Create(nil, lsUserID);
    if (loAddUser.ShowModal = mrOk) then
      tvUsers.Items.Add(tvUsers.TopItem, lsUserID);

Open in new window

Question by:MartinC
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Expert Comment

ID: 24134223
Use this instead, and add the AddUser unit to whichever unit youre calling the dialog from

procedure TfrmUserRoles.mAddUser;
  lsUserID: string;
  if frmAddUser = nil then
    Application.CreateForm(TfrmAddUser, frmAddUser);

  if frmAddUser.ShowModal = mrOK then



Expert Comment

ID: 24134243
Oops, and frmAddUser := nil; after frmAddUser.Release, or you'll get access violations next time you call it.

Author Comment

ID: 24134333

Your method is an alternate way of calling a Modal form (and in fact one I have used before) but I was really hoping to find out why the code I wrote above - which conforms to methods used elsewhere in this app - might not work. The original code seems to be a reasonable way to do it - assign the created form to a local variable of type TfrmAddUser, and free it at the end after reading the returned lsUserID - but the error I get stymies me.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Accepted Solution

LucEngelen earned 60 total points
ID: 24134386
I dont know what your create constructor is doing, since you havent included it in your sample code.

Are you setting form.visible := true in there?  If so that is the reason for the issue.

You cannot call ShowModal once a window has had its visible state changed to true.

You may want to test this by just calling ;
loAddUser := TfrmAddUser.Create(nil);


Author Comment

ID: 24134449
And I wish I HAD included the constructor because then you would no doubt have spotted instantly what I left out:

  inherited create(AOwner);

I just spotted it then myself before reading your last comment, but thanks - and points - for your help anyway.

Expert Comment

ID: 24134571
It happens ;)  Its happened to me so many times I made it a habit to write inherited Create and inherited Destroy as soon as the begin and ends are in place, even if I wasnt working on those functions at the time.


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month7 days, 7 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question