如何检测控件的父表单?

Ole*_*ndr 4 delphi firemonkey-fm3

需要在Delphi中检测父表单(FireMonkey 3)以获取此表单上的任何控件.

最简单的方法是什么?

NGL*_*GLN 7

Root控件的属性指向最上面的Parent.

Root是接口类型IRoot.调用GetObject它会产生表格.形式可以是类型TCustomForm,TCustomForm3D,TForm,TForm3D,所有这些都TCommonCustomForm为祖先:

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;
Run Code Online (Sandbox Code Playgroud)