Form1 triggering a button click on another form fails
Posted on 1997-11-18
I am using Delphi 1.0...
I have one main form with a button and a timer component on it. When the button on Form1 is clicked, the timer is enabled and then I create Form2 and ShowModal it. When the timer event triggers, I want Form2 to be closed automatically, and then I want a message to appear stating "Time is up!". The code below is close to what I want, but not quite. The problem is, the message dialog is appearing BEFORE the Form2 is closed, which seems odd to me. How do I ensure that Form2 is closed before the MessageDlg is displayed?
procedure TForm1.Button1Click(Senter: TObject);
Timer1.Enabled := True;
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.