I created buttons in my coding. 100 buttons.... Each one`s name is "Button" and the row code and then the column code... I wrote a procedure that is used by the OnClick event of those buttons. Now I want to get the name of the specific one I clicked on and the use that name to change only that button`s color. Help please?

In the OnClick event there's Sender. That refers to the clicked button, so you can use

TButton(Self).Color := clYellow;

I cant seem to get that to work.... I created my button like this:

for l := 1 to 10 do
    for t := 1 to 10 do
    begin
    oButton := TButton.Create(Form1);
    with oButton do
      begin
      parent := Form1;
      Width := 80;
      Height := 30;
      left := l * width;
      top := t * Height;
      Name := 'Button' + IntToStr(l) + IntToStr(t);
      OnClick := MyButtonClick;
      end;

The MyButtonClick is my own Procedure that I wrote.... I tried that which you said but it wont work....

Have you placed the code from pritaeas in your MyButtonClick method?

Yes I did... I get an error... "Missing operator or semi-colon"...

Ok I was an idiot.... No error anymore but if i say:

TButton(self).Caption := 'Hello';

Then it changes my Form's caption to hello

Edited 3 Years Ago by happygeek: fixed formatting

I do not understand your last statement. The Caption is the label that appears on the button. The name is the code name used to refer to the button. They can be the same or differ as you choose.

Here is what you can do

procedure TForm1.MyButtonClick (Sender: TObject);
begin
TButton(Sender).Font.Color := clRed;
end;

Sender is the object that fired the event onCLick;

This question has already been answered. Start a new discussion instead.