Board index » delphi » Close a Form "OnShow"

Close a Form "OnShow"

I Create a Form with a Chart on it.

"OnShow" I set the data for the chart (because I get a error-message when I
want to do it "OnCreate")

When some data are not correct, then I want to close this form.

How can I do this?

It's not possible to close a form "OnShow" or "OnActivate"

Thanks for a tip

Willi Khnis
wkueh...@bluewin.ch

 

Re:Close a Form "OnShow"


On Thu, 20 Aug 1998 07:51:34 +0200, "Willi Khnis"

Quote
<wkueh...@bluewin.ch> wrote:
>I Create a Form with a Chart on it.

>"OnShow" I set the data for the chart (because I get a error-message when I
>want to do it "OnCreate")

>When some data are not correct, then I want to close this form.

>How can I do this?

You can do it by posting a WM_CLOSE message in the OnShow, as follows:

   PostMessage(Handle, WM_CLOSE, 0, 0);

However, there may be a brief flicker because the Close message is
only handled after the form is shown.
I don't see how to get around this, if you want to use this method.

It seems better to handle the data setting from outside the form event
methods. So, write a method FillData, that returns a boolean False if
the data are wrong, then show the form with code like

   With MyForm do
   begin
       if not FillData
        then MessageDlg('Wrong!', mtError, [mbOK], 0)
        else ShowModal
   end

hth
David

Quote
>It's not possible to close a form "OnShow" or "OnActivate"

>Thanks for a tip

>Willi Khnis
>wkueh...@bluewin.ch

------------------
David A. Schweizer

iec ProGAMMA, The Netherlands
d.a.schweizer[OK, i don't want any more spam]gamma.rug.nl
guess where the '@' goes ?

Other Threads