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

# TCustomTabControl.MaybeSelectFirstControlOnPage

Updates the ActiveControl on the parent form when the specified page becomes active.

## Declaration

Source position: comctrls.pp line 466

`protected procedure TCustomTabControl.MaybeSelectFirstControlOnPage(`
`APage: TCustomPage`
`); virtual;`

## Description

MaybeSelectFirstControlOnPage is a method used to ensure that the active control on a form is properly updated when the page on the tab control is changed. It prevents the tabbed control from stealing focus if the active control on the parent form is not the tabbed control or one of its child controls.

APage is used to find the next control in the tab order for the page. If a control is found, it is assigned as the ActiveControl on the parent form.

No actions are performed in the method if any of the following conditions are detected:

- The parent form for the tab control has not been assigned.
- APage has not been assigned.
- APage is not visible.
- APage is not enabled.
- APage does not have any child controls.

MaybeSelectFirstControlOnPage is called from the Change method, and occurs when a new value is assigned to the TabIndex property. It occurs after the current Page on the tab control has been made visible and given focus. It is called before the OnChange event handler is signalled.

## Errors

Raises an EAssertionFailed exception if a value has not been assigned to the APage argument.

## Version info

Added in LCL version 3.4.

## See also

TCustomTabControl.ActivePage |  | Caption for the active page in the tabbed control.
TCustomTabControl.ActivePageComponent |  | The active TCustomPage instance for the tabbed control.
TCustomTabControl.Change |  | Performs actions to show or hide pages when the current page is changed.
TCustomTabControl.CanChange |  | Signals the OnChanging event handler prior to updates to PageIndex.
TCustomTabControl.OnChanging |  | Event handler signalled prior to changing the active tab/page on the tabbed control.
TCustomTabControl.OnChange |  | Event handler signalled when the active page (or tab) for the control is changed.
TCustomTabControl.TabIndex |  | Contains the ordinal position for the active Tab in the control.
GetParentForm |  | Gets the form instance for the specified Control.
TCustomForm.ActiveControl |  | Gets or sets the active control on the form.
TWinControl.FindNextControl |  | Returns the preceding or next control in the tab order.