Is it possible to edit a DFM (Delphi's form script format) in such a way that a form closes itself when shown?
I don't code in Delphi, so I'm not familiar with how these forms work, but it seems I could put code (but not standard Delphi code as it seems) in the OnShow or OnCreate events of the form. However, after trying several statements like Close, Exit, FormNameExit, Destroy, etc. won't work (a log will be created, stating the error that the value of the OnShow property was invalid, etc.)
The normal way of closing the form is through a button, but the button doesn't have a OnClick event, just a property, "ModalResult = 1".
Is there a way to make the window close upon opening, some standard function I could put on the OnCreate or OnShow events of the form? Or maybe, creating a checkbox on the form itself, that gives ModalResult = 1? (don't know if this works)
Thanks for any suggestion!
=)
(Note: maybe it's obvious, but I don't have the source.)
EDIT: Seeing some of your comments added while I typed my text-wall clarifies things a bit.
I don't think I understand exactly what you're trying to do, because it doesn't make sense.
It seems to me that you want the form to be automatically closed as soon as it is shown; and that doesn't make sense. :S
So, if I have understood you correctly, please explain why you would want to do this; there may be a better solution for your actual problem.
However, some general concepts...
ModalResult
.ModalResult
has no effect.FormStyle
being the most important) that have an effect on how it behaves, displays, and can be closed. (E.g. MDI Child forms will by default either minimise, or do nothing when closed.)Now, some of the technicalities...
MyForm.Show;
orModalResult := MyForm.ShowModal;
ModalResult
to find out the user's answer and act accordingly.ModalResult
and the form will close itself. An easy way to do this is to assign aModalResult
to the buttons on the form; then the button will automatically set the form'sModalResult
when clicked.MyForm.Close
at the appropriate point in time. NB: Note their are other ways to 'close' a form, but it is better to use this method because it allows you to handle theOnCloseQuery
event which is a mechanism to confirm whether the form is allowed to close.OnCloseQuery
is called to confirm whether the form is allowed to close.OnClose
is called to find out how the form should close (as explained previously).Coming back to your question (which sounds like you want the form closed automatically). Rather than closing the form automatically; just don't bother showing it. This is very easy to do. All forms have a
Visible
property; if set toTrue
, Delphi will automatically show the form normally when it is created. So all you need to do is ensure the property isFalse
.