How do I close a modal form? For that matter, what is the best way to close any form?

Submitted by: Administrator
Generally speaking, you call the form's Close method. This runs the OnClose event, which may decide it doesn't want to close, for example if there is unsaved data in the form. Close doesn't free the memory associated with the form, unless of course you put a call to Release in the form's OnClose event.

If you want to close a form without giving it a chance to argue, call the form's Release method. This is similar to Free, but it allows event handlers (e.g. OnDestroy) to finish running before the memory goes away.

Modal forms "end their modal state" when you set the form's ModalResult property to anything greater than zero. If you put a button on a modal form and set the button's ModalResult property to some value, then when the user clicks on that button the form will close with the result you specified. You can find out what the result was by calling ShowModal as a function; i.e. result := Form.ShowModal.
Submitted by: Administrator

Read Online Delphi Job Interview Questions And Answers