unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ContNrs, StrUtils;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
Labels : TObjectList;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var lk : Integer;
begin
// Objekt-Liste für alle Labels erstellen.
Labels := TObjectList.Create;
// Suche alle Komponenten, deren Namen mit label beginnt.
for lk := 0
to ComponentCount - 1
do begin
if (Components[lk]
is TLabel)
and (StartsText('
label', Components[lk].
Name))
then begin
Labels.Add(Components[lk]);
end;
end;
// for lk
end;
// FormCreate
procedure TForm1.Button1Click(Sender: TObject);
var lk : Integer;
begin
// Schriftfarbe der Labels auf Grün setzen.
for lk := 0
TO Labels.Count - 1
do begin
TLabel(Labels[lk]).Font.Color := clGreen;
end;
// for lk
end;
// Button1Click
procedure TForm1.FormDestroy(Sender: TObject);
begin
// Freigabe der Label-Liste.
FreeAndNil(Labels);
end;
// FormDestroy
end.