naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37916

Get Active Form in FireMonkey Android Application

I'm stuck. How to get an active form in FireMonkey Android application? I have only a TComponent placed on this form, but it seems like it doesn't contain a reference to the root element.

I dynamically create a control (TToolBar) and want to add it to the top of the active form, when component is placed on it. The problem is:

  ToolBar := TToolBar.Create(Application);
  ToolBar.Align := TAlignLayout.alTop;
  ToolBar.Parent := ?;  // I don't know what parent to specify for this control

May be I should instantiate a new form and place the control on it?

Upvotes: 1

Views: 1276

Answers (1)

naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37916

  1. The right solution:

    ToolBar.Parent := Application.MainForm;
    (docs)

  2. This will work, but you will be unable to add childrens to the ToolBar:

    if Application.HasParent then
    ToolBar.Parent := Application.GetParentComponent as TFmxObject;
    (docs)

  3. This internal function should also do the trick in case if you know FormFamily:

    function Application.GetDeviceForm(const FormFamily: string): TCommonCustomForm; overload;

Upvotes: 1

Related Questions