Howdy, Stranger!

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

Categories

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

  • zibadianzibadian Member Posts: 6,349
    : 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]
  • Josh CodeJosh Code Member Posts: 675
    : 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]
  • hhcamiglahhcamigla Member Posts: 31
    : 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;



  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ____ \ http://forcoder.org \ free ebooks and video tutorials about [ Assembly, Objective-C, Delphi, Perl, Visual Basic, Visual Basic .NET, PHP, R, PL/SQL, C, C#, Scratch, Python, Swift, Java, C++, JavaScript, MATLAB, Ruby, Go F#, Alice, ABAP, Scala, FoxPro, Hack, Crystal, Logo, Julia, COBOL, Lisp, Awk, Prolog, Scheme, Transact-SQL, Dart, Clojure, D, Rust, Ada, LabVIEW, Kotlin, Fortran, Lua, Apex, Bash, Erlang, ML, VBScript, SAS ] ________

Sign In or Register to comment.