I am learning Delphi recently but when I want to close a dialog or a form, It works with Close and Free and Destroy commands.
What is the difference between these commands and how should I decide which one to use?
Tform.Close
In VCL closes the form depending on its State. If your FFormState
is FSModal
it will do the cancel Action.
If your Form is MainForm
, the whole apllication will be terminated and so on. For further informations please look into TCustomForm.Close
inside of system.pas
.
In the end the Result will be that you dont see the Form anymore, but that does not mean your Reference to the Form is destroyed.
.free
free also calls destroy, but like David said it is nil reference safe so in most cases you should use free instead of destroy
.destroy
Free
instead ofDestroy
. That is its purpose. As forClose
, that depends on the form. – Jerry Dodge