How detects parent form for Control?

1.8k views Asked by At

Need to detect the Parent Form in Delphi (FireMonkey 3) for any Control on this form.

What is the easiest way for it?

1

There are 1 answers

0
NGLN On BEST ANSWER

The Root property of a control points to the uppermost Parent.

Root is of interface type IRoot. Calling GetObject on it results in the Form. The Form can be of type TCustomForm, TCustomForm3D, TForm, TForm3D, all which have TCommonCustomForm as ancestor:

function GetParentForm(Control: TFmxObject): TCommonCustomForm;
begin
  if (Control.Root <> nil) and
      (Control.Root.GetObject is TCommonCustomForm) then
    Result := TCommonCustomForm(Control.Root.GetObject)
  else
    Result := nil;
end;