Solved

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

Posted on 1997-11-17
3
148 Views
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?
0
Comment
Question by:Kapusta
[X]
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
3 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 50 total points
ID: 1350787
Maybe
if assigned(TForm2) then (Form2 is created)
Check ComponentState property for testing open and destroy state
0
 
LVL 4

Expert Comment

by:StevenB
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.

  Steven.
0
 

Author Comment

by:Kapusta
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);
begin
      Timer1.Enabled := True;
      Form2:= TForm2.Create(Application);
      try
            Form2.ShowModal;
      finally
            Form2.Free;
      end;
end;

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

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

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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