Re: Changing properties

Posted by Eric on March 20, 2008

In Reply to 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 correct way to do it? It seems convoluted that I have to use labels to associate everything.
: Thanks for the advice!

Your code is correct, you can't simplify it if you want to change properties of several components, each with their own button, but still using a common onclick-event-handler.

Of course, the code becomes much simpler if you have 1 button per label/shape pair:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Label1.Font.Color = clBlack then 
    Label1.Font.Color := clRed
  else 
    Label1.Font.Color := clBlack;
  Shape1.Visible := not Shape1.Visible;
end;

Related articles

       

Follow Ups