Board index » delphi » Closing a modal or non-modal Form

Closing a modal or non-modal Form

Hi,

is there a way that a form can find out whether it is being displayed
modally or non-modally? FFormState is private - another case of "too
private".

I have a Form that i display modal and non-modal according to context.
This is a sort of property-editor (not in the delphi sense) and
sometimes properties need to be set "right now" (notable when creating
new objects) and at other times i want the editor to just sit there
floating.

I can show the editor using Show and ShowModal alternately, no
problem. The problem arises when closing the Form.

There is an OK-Button on the editor and i naturally want the form to
close when that button is hit but i need some processing before it
closes. So i have code like

  procedure TPropertyEditor.OKBtnClick(Sender:TObject);
    begin
      if Validate then Close;
    end;

This works for the non-modal-Version. The modal-Version would need a
'ModalResult:=mrOK' instead of the 'Close'. No way to have both as
Close clobbers the ModalResult to mrAbort and the assignment to
ModalResult does not close a non-modal Form.

I know about OnCloseQuery and how to use that for validation but in my
case things are more complicated.

Ciao, MM
--
Fon: +49 228 624013 Fax: +49 228 624031
"Was schiefgehen kann, geht auch schief."

 

Re:Closing a modal or non-modal Form


Quote
Marian Maier wrote:

> Hi,

> is there a way that a form can find out whether it is being displayed
> modally or non-modally? FFormState is private - another case of "too
> private".

> I have a Form that i display modal and non-modal according to context.
> This is a sort of property-editor (not in the delphi sense) and
> sometimes properties need to be set "right now" (notable when creating
> new objects) and at other times i want the editor to just sit there
> floating.

> I can show the editor using Show and ShowModal alternately, no
> problem. The problem arises when closing the Form.

> There is an OK-Button on the editor and i naturally want the form to
> close when that button is hit but i need some processing before it
> closes. So i have code like

>   procedure TPropertyEditor.OKBtnClick(Sender:TObject);
>     begin
>       if Validate then Close;
>     end;

> This works for the non-modal-Version. The modal-Version would need a
> 'ModalResult:=mrOK' instead of the 'Close'. No way to have both as
> Close clobbers the ModalResult to mrAbort and the assignment to
> ModalResult does not close a non-modal Form.

> I know about OnCloseQuery and how to use that for validation but in my
> case things are more complicated.

> Ciao, MM
> --
> Fon: +49 228 624013 Fax: +49 228 624031
> "Was schiefgehen kann, geht auch schief."

OK, I put an ordinary bitbtn on a form. I did not give it any special
style like Kind:=bkClose, for instance. In the click handler I set a
flag to indicate that the close request came from my close button. In
the OnCloseQuery handler I set the modal result depending on the flag.
The form closes when requested, regardless whether it was Show or
ShowModal, and the result when ShowModal is the one set in the
OnCloseQuery handler.
Dave Bolt/UK
Analyst/Programmer
Delphi & C/C++

Other Threads