How to identify if a TForm is created yet and open?

Posted on 1997-11-17
Medium Priority
Last Modified: 2010-04-04
I need a way for Form1 to know if Form2 is created and open.  Form1 is my Main (auto-created) form.  Form2 is created "on-the-fly" with a .Create method, and is then displayed with a .Show method.  Form2 does NOT have a caption, BTW.  How can I detect whether Form2 is created and open?
Question by:Kapusta
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

Accepted Solution

Waldek earned 100 total points
ID: 1350787
if assigned(TForm2) then (Form2 is created)
Check ComponentState property for testing open and destroy state

Expert Comment

ID: 1350788
 It's improtant to realise that this will only check whether Form2 <> Nil. If you ever destroy Form2 then it will still return  True to the above call, unless you explicitly set Form2 := Nil, after the Free method.


Author Comment

ID: 1350789
Here is what I am trying to do...  do I need to add "Form2 := nil" as SteveB suggests?

procedure TForm1.Button1Click(Senter: TObject);
      Timer1.Enabled := True;
      Form2:= TForm2.Create(Application);

procedure TForm1.Timer1Timer(Sender: TObject);
      Timer1.Enabled := False;
      if Assigned(Form2) then begin
      MessageDlg('Time is up!',mtInformation, [mbOk], 0);

I want to force the Form2 to close SHOULD it be open when the timer on Form1 triggers.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

801 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