Changing properties

Posted by Marc M on March 12, 2008

I'm new to Delphi (1 week) and I must say it is great!
I created an app that needs to change a label color and a shape color when a buton is pressed. Below is the code. Is this the coreect way to do it. It seems convoluted that I have to use labels to associate everything. Thanks for the advice!

procedure TForm2.bSwClick(Sender: TObject);
var e: TButton;
i: integer;
begin
e := Sender as TButton;
for i := 0 to componentcount - 1 do
begin
if components[i] is TLabel then
if components[i].tag = e.tag then
if Tlabel(components[i]).Font.Color = clBlack then
Tlabel(components[i]).Font.Color := clRed
else
begin
Tlabel(components[i]).Font.Color := clBlack;
end;
begin
if components[i] is TShape then
if Tshape(components[i]).tag = e.tag then
Tshape(components[i]).Visible := not (Tshape(components[i]).Visible);
end;
end;
end;

Related articles

       

Follow Ups