If you have a large Form with many components on it, and you wish to assign all of the components of a certain type the same property, you may find that you have to code the same assignment line for every component on the form that meets your need.
There is a way to streamline this process using the Components array on the Form. This is a Delphi collection object (available with any descendant of TComponent), that lists all of the components contained on the Form.
Here is a code example that demonstrates how you could disable all of the buttons on a Form that are TButton components:
procedure TForm1.DisableAllButtons;
var
x : integer;
begin
for x := 0 to (Form1.ComponentCount - 1) do
begin
if (Form1.Components[x] is TButton) then
TButton(Form1.Components[x]).Enabled := False;
end;
end;
In this code example, all of the labels on the form will be assigned the same caption. The labels all have the same characteristic - that is, their object names are all "Label##" where "##" is the numeric suffix automatically assigned by the component editor when the TLabel is dropped on the Form:
pprocedure TForm1.SetAllCaptions;
var
x : integer;
begin
for x := 0 to (Form1.ComponentCount - 1) do
begin
if (Form1.Components[x] is TLabel) then
if (Copy(TLabel(Form1.Components[x]).Name,1,5) = 'Label') then
And remember, if the changes you want to make can be made at design time, you can simply open the form in text mode and use the Edit/Replace commands from the toolbar to make the changes to the form. Since the IDE is a two-way operation, any changes you make to the form will be immediately reflected in the code.
-Larry Drews