----- Original Message -----
From: "Mark Derricutt" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Tuesday, August 20, 2002 9:07 PM
Subject: [DUG]: Strange TTimer/ShowModal behaviour (kylix)


> 'lo all, have a strange problem afflicting a kylix 2 application.
>
> Take a project with 2 forms, Form1 & Form2, put a TTimer on Form1, and
give
> it the following code:
>
>   procedure TForm1.Timer1Timer(Sender: TObject);
>   begin
>     Form2.ShowModal;
>     Caption := 'Boo';
>   end;
>
> Form2 displays, but shortly afterwards, about a second, Form1's caption is
> set to Boo, whilst the modal form is still displayed.

Your timer will continue to tick after the ShowModal.  The next time (and
every time) the timer fires it will fail on ShowModal (because the form is
already visible), and go on to set the caption of Form1.  I'd suggest
disabling the timer before calling ShowModal.

> I've just tried the exact same thing under Delphi 5, and shortly after
> Form2 is displayed, I get an exception saying "EInvalidOperation with
> message 'Cannot make a visible window modal".

This is probably more correct behavior than Kylix, but it's probably a
difference between the basic component implementations.  I would call it a
bug, but I couldn't say for sure whether it was a bug in Kylix or Delphi.

> I noticed that Form2 was still in the AutoCreate list, removing it, and
> creating/freeing a TForm2 instance in the timer solved the problem in both
> the Delphi and Kylix versions.

Really?  I would think that you'd end up with multiple visible copies of the
form, all modal.

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to