TPanel   *pp   =   dynamic_cast <TPanel   *> (Sender);
    TLabel   *ll   =   dynamic_cast <TLabel   *> (Sender);

  if   (!pp   &&   ll)
        pp   =   dynamic_cast <TPanel   *> (ll-> Parent);

    if   (pp)
        ShowMessage(pp-> Caption);

var
    pp:   TPanel;
    ll:   TLabel;
begin
    pp   :=   Sender   as   TPanel;
    ll   :=   Sender   as   TLabel;
    if   (pp   <>   nil)   and   (ll   <>   nil)   then
        pp   :=   Parent   as   TPanel;
    if   (pp   <>   nil)   then
        ShowMessage(pp.Caption);
end;

//void   __fastcall   TForm1::lwv(TObject   *Sender)
procedure   TForm1.lwv(Sender:TObject);
//{TPanel   *pp   =   dynamic_cast <TPanel   *> (Sender);
//     TLabel   *ll   =   dynamic_cast <TLabel   *> (Sender);

var
    pp:TPanel;
    ll:TLabel;
begin
    pp:=nil;
    ll:=nil;

    if   Sender   is   TPanel   then
        pp:=Sender   as   TPanel;

    if   Sender   is   TLabel   then
        ll:=Sender   as   TLabel;

  //if   (!pp   &&   ll)
    if(Not   Assigned(pp))   and   Assigned(ll)   then
        //pp   =   dynamic_cast <TPanel   *> (ll-> Parent);
        if   Assigned(ll.Parent)   then
            if   ll.Parent   is   TPanel   then
                pp:=ll.Parent   as   TPanel;

    //if   (pp)
    if   Assigned(pp)   then
        //ShowMessage(pp-> Caption);
        ShowMessage(pp.Caption);

//               }
end;

学习下