?
Solved

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

Posted on 1997-11-17
3
Medium Priority
?
156 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
3 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 100 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

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 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