Tnotifyevent

Hello,

i have an array of Tpanel. I create them at runtime and give then names. Then i compare mas[i].onclick := myonclick; So what button you press it calls procedure myonclick(sender: tobject);

My problem is how to know the name of Tpanel which i clicked. How get the name or tag???

Comments

  • : Hello,
    :
    : i have an array of Tpanel. I create them at runtime and give then names. Then i compare mas[i].onclick := myonclick; So what button you press it calls procedure myonclick(sender: tobject);
    :
    : My problem is how to know the name of Tpanel which i clicked. How get the name or tag???
    :
    The sender is the object, which was clicked by the user. You still need to perfrom the correct type-casting. Here is a small example featuring a button and a label:
    [code]
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Label1.Caption := (Sender as TButton).Name;
    end;
    [/code]
  • : Hello,
    :
    : i have an array of Tpanel. I create them at runtime and give then names. Then i compare mas[i].onclick := myonclick; So what button you press it calls procedure myonclick(sender: tobject);
    :
    : My problem is how to know the name of Tpanel which i clicked. How get the name or tag???
    :
    [code]
    [b]procedure[/b] Myonclick(sender: tobject);
    [b]var[/b]
    pe: integer;
    // element in the mas array
    [b]begin
    if[/b] sender is tpanel [b]then[/b] // make sender the object is a panel
    [b]begin
    for[/b] pe:=high(mas) [b]downto[/b] 0 [b]do[/b] // loop through the array
    [b]if[/b] mas[pe]=(sender as tpanel) [b]then[/b]
    break;
    // break the loop when sender is found in the array
    [b]end
    else[/b]
    ShowMessage('The sender is not a panel.');
    // now pe should be the index of sender in the array of tpanel

    [b]end;[/b]
    [/code]
  • : Hello,
    :
    : i have an array of Tpanel. I create them at runtime and give then names. Then i compare mas[i].onclick := myonclick; So what button you press it calls procedure myonclick(sender: tobject);
    :
    : My problem is how to know the name of Tpanel which i clicked. How get the name or tag???
    :


    this coding might help you
    procedure TForm1.MyOnclick( Sender );
    begin
    if Sender is TPanel
    then ShowMessage(TPanel(Sender).Name);
    end;



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories