Board index » delphi » Cannot close form on Error

Cannot close form on Error

Hi all,

In the FormShow procedure, I have the following coding:
with dataModule
begin
    try
        select * from aTable where accoring to some criteria
    except
        ShowMessgage('Error');
        close; // or self.close
    end;//try
end;//with

But, I find out that the
    close; // or self.close
cannot close the form.

So, in case of database error,
the form still show.

Any idea why ?

Alvin SIU

 

Re:Cannot close form on Error


Actually, there is a parent form with 7 buttons.  The button-1's onClick event
is like this:
    hide
    set-flag to 1
    myForm.ShowModal
    show
For button-2 to button-7, they will set-flag-to-2 and set-flag-to-7
accordingly.
Then, they all call the same myForm.

Then, myForm's onShow event will
    'select * according to the criteria basing on the flag'

For example,
button-1 will select those black-hair customers
button-2 will select those white-hair customers
button-3 will select those brown-hair customers
button-4 will select those red-hair customers
...
Of course, my appliction is more complicate on the selection criteria.

But, is there other ways to do this kind of things ?

Alvin SIU

Quote
steve evans wrote:
> You can't change the visibility of a form inside an 'onshow' or 'onhide'
> event.

> What are you trying to do? Are you showing the form, then deciding whether
> or not to close it?
> If this is the case, then you should really check your conditions before
> even showing the form.
> if  condition=true then form1.show;
> Alternatively, if you are doing the check from within the form, then don't
> try and close it in the Show procedure!

> "Alvin SIU" <alvin...@hkstar.com> wrote in message
> news:3DC12515.72A33F8C@hkstar.com...
> > Hi all,

> > In the FormShow procedure, I have the following coding:
> > with dataModule
> > begin
> >     try
> >         select * from aTable where accoring to some criteria
> >     except
> >         ShowMessgage('Error');
> >         close; // or self.close
> >     end;//try
> > end;//with

> > But, I find out that the
> >     close; // or self.close
> > cannot close the form.

> > So, in case of database error,
> > the form still show.

> > Any idea why ?

> > Alvin SIU

Other Threads