4

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

最简单的方法是什么?

4

1 回答 1

7

控件的Root属性指向最上面的父级。

根是接口类型IRoot。调用GetObject它会生成表单。Form 可以是, , ,类型TCustomForm,所有这些类型都是祖先:TCustomForm3DTFormTForm3DTCommonCustomForm

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;
于 2013-12-05T17:15:58.127 回答