4

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

What is the easiest way for it?

Oleksandr
  • 319
  • 1
  • 6
  • 15

1 Answers1

7

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;
NGLN
  • 43,011
  • 8
  • 105
  • 200