Solved

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

Posted on 1997-11-17
3
143 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 50 total points
Comment Utility
Maybe
if assigned(TForm2) then (Form2 is created)
Check ComponentState property for testing open and destroy state
0
 
LVL 4

Expert Comment

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

14 Experts available now in Live!

Get 1:1 Help Now