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

TCustomForm.ActiveControl

Gets or sets the active control on the form.

Declaration

Source position: forms.pp line 762

public property TCustomForm.ActiveControl : TWinControl
  read FActiveControl
  write SetActiveControl;

Description

ActiveControl is a TWinControl property which contains the control which has focus on the form. The property can contain Nil if the parent form is hidden, disabled, or has never been activated.

Setting a new value for the property performs validity checks to ensure that the specified control can receive focus when the form is Visible. An EInvalidOperation exception is raised with the message in SCannotFocus when the new property value contains:

The value in the LastActiveControl property is updated with the existing value for ActiveControl if it is a control and not a TForm/TCustomForm instance. If the form (and not a control) was active, LastActiveControl is set to Nil.

At run-time, the new active control is focused and activated if its form is active (Active = True). ActiveChanged is called too. Both of these steps are omitted at design-time or when the component is loaded during component streaming.

The value in ActiveControl is updated in the FocusControl and DefocusControl methods.

See also

TCustomForm.LastActiveControl

  

Tracks focus changes for the active form or the last active control on the current form.

TCustomForm.Active

  

Indicates if the form is enabled, visible, and has focus.

TCustomForm.ActiveChanged

  

An empty implementation in TCustomForm.

TCustomForm.FocusControl

  

Gives focus to the specified control.

TCustomForm.DefocusControl

  

Updates ActiveControl if it is to be de-focused.

GetParentForm

  

Gets the form instance for the specified Control.

#lcl.controls.TWinControl.CanFocus

  

Is this control allowed to receive the focus when parent form is visible?


Version 4.0 Generated 2025-05-03 Home