I would like to create a procedure that returns me the name of the form where the object is allocated. For example:
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.
How do?
LE:
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;
It seems to me that the procedure
GetParentForm
declared inForms
unit does what you want. Take a look athttp://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Forms_GetParentForm.html