Vcl.Controls.TWinControl.GetControls

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function GetControls(AFilter: TControlEnumeratorFilter = []): TControlEnumerator;

C++

TControlEnumerator* __fastcall GetControls(TControlEnumeratorFilter AFilter = TControlEnumeratorFilter() );

Properties

Type Visibility Source Unit Parent
function public
Vcl.Controls.pas
Vcl.Controls.hpp
Vcl.Controls TWinControl

Description

GetControls returns the control of the TControlList.

GetControls is the protected read implementation of the Controls property.

Example

The following examples show how to use GetControls and TControlEnumeratorFilter in code.

Delphi

 for var ACtrl in Panel1.GetControls do
  begin
    // This gets all controls of 'Panel1'
  end;
 
  for var ACtrl in Panel1.GetControls([ceftEnabled]) do
  begin
    // This gets all enabled controls of 'Panel1'
  end;
 
  for var ACtrl in Panel1.GetControls([ceftVisible]) do
  begin
    // This gets all visible controls of 'Panel1'
  end;

Notice that the default control enumerator still defaults to the TComponent enumerator, so if you write:

 for var ACtrl in Panel1 do
  begin
    // This gets all components of 'Panel1'
  end;

You are actually enumerating all components owned by the instance (for example 'Panel1' in our example) and not only its controls.

Enumerate controls of the same object using the code below.

for var ACtrl in GetControls([ceftAll]) do
begin
end;

C++

With the following code, you can update the Caption of a Form to include the ClassName of each control within square brackets.

  String msg;
  for (auto ctl: GetControls(TControlEnumeratorFilter()))
  {
	msg += "[" + ctl->ClassName() + "]";
  }
  Caption = msg;

See Also