[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Dialogs' (#lcl)

# TFileDialog.DoCanClose

Performs actions needed to determine if the dialog can be closed.

## Declaration

Source position: dialogs.pp line 164

`public procedure TFileDialog.DoCanClose(`
`var CanClose: Boolean`
`); override;`

## Arguments

`CanClose` |  | Contains True if the dialog can be closed. False to prevent the dialog from being closed.

## Description

DoCanClose is an overridden method in TFileDialog used to perform actions needed when an attempt is made to close the dialog. It ensures that the inherited method is called only when the OK button was pressed on the dialog. If the Esc key was pressed, or the dialog is closed using the close icon, the inherited method is not called. This prevents the OnCanClose event from being signalled when the dialog has actually been cancelled. CanClose is set to True in this situation.

This is done to maintain compatibility with Delphi VCL behavior.

Use the OnCanClose event handler to perform validation or error checking needed for the value in FileName. Set the value in its CanClose argument to False to prevent closing the dialog form.

## See also

TFileDialog.FileName |  | Contains the UTF-8-encoded name for a file chosen using the dialog.
TCommonDialog.UserChoice |  | Contains the modal result value selected by the user.
TCommonDialog.DoCanClose |  | Performs actions needed to determine if the dialog can be closed.
TCommonDialog.OnCanClose |  | Event handler signalled to determine if the dialog can be closed.
TCommonDialog.OnDialogResult |  | Event handler signalled when a result is available for the dialog.