- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3216:Looping Through the Controls and Components Arrays

KEYWORDS: controls, components, array, parent, owner, TWinControl AREA: All

There are 2 important properties in Delphi that everyone using the product
should know about. The components array is a property of all components
that own other components. The controls array is a property of all
TWinControls that are parents of TWinControls. These properties are so
important because they allow you to iterate through a group of components
without knowing the names or knowing what type of controls or components
they are. This could be important for example if you wanted to disable or
enable all the controls on a form or within a container control (  such as
a panel). Proper code for this iterative process is shown below for both
cases.

1. Iteration through the components array of the form:

begin
  for i:= 0 to componentcount - 1 do
  begin
    {enter the code to act on each member of the array here}
  end;
end;

2. Iteration through the controls array of the form:

begin
  for i:= 0 to controlcount - 1 do
  begin
    {enter the code to act on each member of the array here}
  end;
end;

The variable 'i' is an integer declared for iteration one array member at
a time and must be declared by the user. The variables controlcount and
componentcount are additional properties of TWinControl and TComponent
respectively. These properties are often used in conjunction with iteration
through the corresponding array properties.

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile