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

# TCustomForm.AddHandlerClose

Adds a handler for a form close event.

## Declaration

Source position: forms.pp line 747

`public procedure TCustomForm.AddHandlerClose(`
`OnCloseHandler: TCloseEvent;`
`AsFirst: Boolean = False`
`);`

## Arguments

`OnCloseHandler` |  | Form close handler routine added in the method.
`AsFirst` |  | True if the handler is stored as the first entry in the list of form close handlers.

## Description

AddHandlerClose is a method used to add the TCloseEvent handler specified in OnCloseHandler to the list of form handlers for the type. It allows a form instance to have additional event handlers which behave just like the OnClose event handler.

AddHandlerClose calls the AddHandler method to create the TMethod entry used to represent the handler routine. When AsFirst is True, the routine in OnCloseHandler is inserted as the first item in the list of form close handlers.

Applications must implement and assign an object procedure using the signature in TCloseEvent to perform actions needed when the Close or CloseModal method is called for the form instance.

A handler added using AddHandlerClose is signalled after the OnClose event handler for the form instance.

Use RemoveHandlerClose to remove a form close handler added in the method.

## See also

TCustomForm.Close |  | Closes the form.
TCustomForm.OnClose |  | Handler called when the form is closed. It determines what happens to the form (destroy, hide, etc.).
TCustomForm.RemoveHandlerClose |  | Removes a form close handler added to the form instance.
TCloseEvent |  | Type used for an OnClose event handler in a form.