Board index » delphi » Modal or Modeless: How does a form know?

Modal or Modeless: How does a form know?

How does a form know if it is being displayed as a modal or modeless
window?

The problem is that ModalResult:=mrWhatever does not close the form unless
it has been shown modally. I have forms that are shown both modally and
modelessly depending upon certain circumstances.

Thanks muchly

---
Michael J. Leaver
mich...@sunway.com.sg (Business)
mic...@pacific.net.sg (Personal)

 

Re:Modal or Modeless: How does a form know?


Michael J Leaver wrote in article
<01bcc7c8$d20a2c80$9684a...@michael.pacific.net.sg>...

Quote
>How does a form know if it is being displayed as a modal or modeless
>window?

>The problem is that ModalResult:=mrWhatever does not close the form unless
>it has been shown modally. I have forms that are shown both modally and
>modelessly depending upon certain circumstances.

>Thanks muchly

>---
>Michael J. Leaver
>mich...@sunway.com.sg (Business)
>mic...@pacific.net.sg (Personal)

Forms are declared as modal thru the showmodal function.

MyForm1.Showmodal;

The function then returns an integer describing how the form was closed.  A
number of constants have be declared (like mrCancel) to simplify the
interpretation of the function's result (in this case ModalResult).  So the
program 'knows' if it is modal or not depending on how the form is opened
(shown) by the user.

Brien Smith
br...@tassoft.com

Re:Modal or Modeless: How does a form know?


Quote
>Michael J Leaver wrote in article
><01bcc7c8$d20a2c80$9684a...@michael.pacific.net.sg>...

>>How does a form know if it is being displayed as a modal or modeless
>>window?

>>The problem is that ModalResult:=mrWhatever does not close the form unless
>>it has been shown modally. I have forms that are shown both modally and
>>modelessly depending upon certain circumstances.

>>Thanks muchly

>>---
>>Michael J. Leaver
>>mich...@sunway.com.sg (Business)
>>mic...@pacific.net.sg (Personal)

From looking at the source, there is a private field (FFormState)
which 'knows' whether the form is modal. However, the only way to
access it is by modifying FORMS.PAS. ShowModal is handling all mesages
in its own loop, and there appears to be no other simple way to detect
modal/nonmodal. Apart from looking at clues like whether the main form
is enabled or not (which could conceivably be done) the best solution
seems to be to set an indicator yourself (you could use the Tag field
of the forms for this) before Show or ShowModal.

hth
David

------------------
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