Solved

"Cannot make a visible Window modal"

Posted on 2009-04-13
6
2,676 Views
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:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21234459.html

... but nothing there seemed to make it work either. Any ideas, anyone?
procedure TfrmUserRoles.mAddUser;

var

  loAddUser: TfrmAddUser;

  lsUserID: string;

begin

  loAddUser := TfrmAddUser.Create(nil, lsUserID);

  try

    if (loAddUser.ShowModal = mrOk) then

      tvUsers.Items.Add(tvUsers.TopItem, lsUserID);

  finally

    loAddUser.Free;

  end;

end;

Open in new window

0
Comment
Question by:MartinC
  • 4
  • 2
6 Comments
 

Expert Comment

by:LucEngelen
Comment Utility
Use this instead, and add the AddUser unit to whichever unit youre calling the dialog from

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

  if frmAddUser.ShowModal = mrOK then
    ...

  frmAddUser.Release;
end;

0
 

Expert Comment

by:LucEngelen
Comment Utility
Oops, and frmAddUser := nil; after frmAddUser.Release, or you'll get access violations next time you call it.
0
 

Author Comment

by:MartinC
Comment Utility
LucEngelen:

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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
LucEngelen earned 60 total points
Comment Utility
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);
loAddUser.ShowModal;


0
 

Author Comment

by:MartinC
Comment Utility
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.
0
 

Expert Comment

by:LucEngelen
Comment Utility
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.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now