Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How detects parent form for Control?

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

What is the easiest way for it?

like image 635
Oleksandr Avatar asked Mar 21 '23 10:03

Oleksandr


1 Answers

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;
like image 59
NGLN Avatar answered Apr 01 '23 11:04

NGLN