title: How to discover owner from object in Delphi?
body: <p>I would like to create a procedure that returns me the name of the form where the object is allocated. For example:</p>
  
  <p>I have a TPanel and within TPanel one TButton. I'll pass as a parameter to the function name of TButton and want the function to return me the name of formuário where is this button.</p>
  
  <p>How do?</p>
  
  <p>LE: </p>
  
  <pre><code>function TForm1.DoSomething(Obj: TComponent): String; 
  var AClass : String; I : Integer; 
  begin 
   AClass := TComponent(Obj).Owner.ClassName; 
   if (AClass = 'TForm') then 
    Result := TComponent(Obj).Name 
  else 
   Result := TComponent(Obj).Owner.Name; 
  end; 
  
  procedure TForm1.Button1Click(Sender: TObject); 
  begin 
   NomeForm := DoSomething(Button3); 
   ShowMessage(NomeForm); 
  end; 
  
  procedure TForm1.Button4Click(Sender: TObject); 
  begin 
   NomeForm := DoSomething(Form1); 
   ShowMessage(NomeForm); 
  end; 
  </code></pre>