Link to home
Start Free TrialLog in
Avatar of Kapusta
Kapusta

asked on

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

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?
ASKER CERTIFIED SOLUTION
Avatar of Waldek
Waldek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of StevenB
StevenB

 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.
Avatar of Kapusta

ASKER

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.