Show: Delphi C++
Display Preferences

FMX.Controls.TControl.EnumControls

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure EnumControls(const Proc: TFunc<TControl, TEnumControlsResult>); overload;
function EnumControls(Proc: TEnumControlsRef; const VisibleOnly: Boolean = True): Boolean; overload;

C++

void __fastcall EnumControls(const System::DelphiInterface<System::Sysutils::TFunc__2<TControl*,Fmx::Types::TEnumProcResult> > Proc)/* overload */;
bool __fastcall EnumControls _DEPRECATED_ATTRIBUTE1("Use another version of EnumControls") (_di_TEnumControlsRef Proc, const bool VisibleOnly = true)/* overload */;

Properties

Type Visibility Source Unit Parent
procedure
function
public
FMX.Controls.pas
FMX.Controls.hpp
FMX.Controls TControl

Description

Loops through the controls that are children of this control, and runs the specified procedure once per control, with a different control as the first parameter in each call.

Warning: EnumControls is deprecated as a function. You should use it as a procedure instead. This page describes the syntax and use of the EnumControls procedure.

EnumControls loops not only through direct children of this control, but also through their children (grand-children), and so on, using a depth-first search algorithm.

Each time EnumControls visits a control during the search, it executes the Proc procedure. This procedure receives the visited control as argument, and it returns a value of type TEnumControlsResult. The return value defines what EnumControls does next. You may return any of the following values:

  • Continue lets EnumControls keep searching the controls as usual.
  • Discard makes the search skip the children of the current control (the control in the first parameter), as well as their children (grand-children) and so on.
  • Stop interrupts the search loop. If EnumControls were a language-level control loop, Stop would be the Break keyword.

Example

The following is an example call to EnumControls that loops through the children of a panel (Panel1) and fills a list (ListOfVisibleControls) with all the controls that are visible:

In Delphi:

Panel1.EnumControls(function (Control: TControl): TEnumControlsResult
  begin
    if not Control.Visible then
      Result := TEnumControlsResult.Discard
    else
      begin
        ListOfVisibleControls.Add(Control);
        Result := TEnumControlsResult.Continue;
      end;
  end);

In C++:

1. Define a class that implements the TFunc__2 interface:
class TMethodReference : public TCppInterfacedObject<TFunc__2<TControl*,TEnumControlsResult> >
{
public:
    TEnumControlsResult __fastcall Invoke(TControl* Control)
    {
        if (!Control->Visible)
            return TEnumControlsResult::Discard;
        else {
            TForm2::ListOfVisibleControls->Add(Control);
            return TEnumControlsResult::Continue;
        }
    }
};
2. Then pass an instance of this class to EnumControls:
Panel1->EnumControls(new TMethodReference);

See Also

Personal tools
In Other Languages
Previous Versions
Assistance