Use the OnExit event handler to provide special processing when the control ceases to be active.

The OnExit event does not occur when switching between forms or between another application and your application.

When switching between controls in separate container controls such as the TPanel and the TGroupBox controls, an OnExit event occurs for the control inside the container before the OnExit event of the container.

Similarly, an OnEnter event of the container occurs before the OnEnter event of the control in a container when focus moves to a control inside a container.

For example, consider a form with an OK button and a group box that contains three radio buttons, where focus is currently on the OK button. When the user clicks one of the radio buttons, an OnExit event of the button occurs, followed by an OnEnter event on the group box, and finally an OnEnter event on the radio button that was clicked. If the user then clicks on the OK button, an OnExit event for the radio button occurs followed by an OnExit event for the group box, and then the button's OnEnter event occurs.

Note: In some control classes the ActiveControl property updates before the OnExit event occurs.

/*
This example uses an edit box and a memo control on a form.
When either the edit box or the memo is the active control,
it is colored yellow. When the active control becomes
inactive, the color of the control returns to the Windows
system color for a window. These event handlers could also
be shared.
*/void__fastcall TForm1::Edit1Enter(TObject *Sender)
{
Edit1->Color = clYellow;
}
//---------------------------------------------------------------------------void__fastcall TForm1::Edit1Exit(TObject *Sender)
{
Edit1->Color = clWindow;
}
//---------------------------------------------------------------------------void__fastcall TForm1::Memo1Enter(TObject *Sender)
{
Memo1->Color = clYellow;
}
//---------------------------------------------------------------------------void__fastcall TForm1::Memo1Exit(TObject *Sender)
{
Memo1->Color = clWindow;
}

{
This example uses an edit box and a memo control on a form.
When either the edit box or the memo is the active control,
it is colored yellow. When the active control becomes
inactive, the color of the control returns to the Windows
system color for a window. These event handlers could also
be shared.
}procedure TForm1.Edit1Enter(Sender: TObject);
begin
Edit1.Color := clYellow;
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
Edit1.Color := clWindow;
end;
procedure TForm1.Memo1Enter(Sender: TObject);
begin
Memo1.Color := clYellow;
end;
procedure TForm1.Memo1Exit(Sender: TObject);
begin
Memo1.Color := clWindow;
end;