Using FireMonkey Views

From RAD Studio
Jump to: navigation, search

Go Up to FireMonkey Application Design


Views are a mechanism that allows you to define a different layout and components for the forms of your application depending on the device where your application is running.

New forms contain a single view: the Master view. The Master view is the view that your application loads if your application does not contain any other view fit for the device where your application is running. You can add more views to your application if you want to provide a different view on a specific kind of device. These additional views are customized versions of the Master view for a given device or a type of device that inherits all the components and modifications from the Master view.

You can use the View Selector of the Form Designer to add or remove views from your form. You can also create custom views.

MultipleViews.png

View Inheritance

Any additional view that you add to your project inherits the components of the Master view and their properties.

When you add or remove components from the Master view, the Form Designer propagates this change to any existing view. You can only add or remove components from the Master view, you cannot add or remove components from any other view. If you only want one component to show up on certain views, hide that component on any other view.

When you change properties of your form or any of its components on the Master view, the Form Designer propagates those changes as well to any existing view unless that view has already specified a different value for that property. You can customize property values on any particular view to overwrite the value from the Master view only on the candidate view.

Restoring the Property Values of a Component from Master

To restore the property values from the Master view on a component of another view:

  1. Select the candidate view from the View Selector.
  2. On the Form Designer, right-click the target component.
  3. Select Revert to Inherited from the context menu.

All the properties of the selected component go back to the value that they have in the Master view.

Hiding a Component

You cannot remove a component from a view, but you can hide that component.

To hide a component on a particular view:

  1. Select the component.
  2. On the Object Inspector, set the Visible property to False.

To hide a component for a specific target platform, use conditional code in the Code Editor:

Delphi:

{$IFDEF ANDROID}
    SpeedButton1.Visible := False;
{$ENDIF}

C++:

#if defined(__ANDROID__) && defined(__arm__)
    SpeedButton1->Visible = false;
#endif

You can run this code from an event handler associated with the OnCreate event of your form, for example. Since you are changing the visibility of the component at run time, the component is still visible on the Form Designer.

View Loading Algorithm

When you run your application on a device, FireMonkey evaluates the views defined in your application, and lists them by priority. The list includes only views where the platform is the same as the platform where your application is running, and the priority of each view in the list is determined according to the following criteria, from highest (1) to lowest priority:

Priority Requirements

1

  • The diagonal of the device where your application is running is withing the diagonal range of the candidate view: [minimum diagonal, maximum diagonal].
  • Of the diagonal ranges of all the views, the diagonal range of the candidate view is closest to the diagonal of the device where your application is running.
  • The device class of the candidate view is the same as the class of the device where your application is running.

2

  • The diagonal of the device where your application is running is withing the diagonal range of the candidate view: [minimum diagonal, maximum diagonal].
  • Of the diagonal ranges of all the views, the diagonal range of the candidate view is closest to the diagonal of the device where your application is running.
  • The device class of the candidate view is different from the class of the device where your application is running.
  • The candidate view is not exclusive.

3

Note: Views with this priority level are sorted by the difference between the mean of the diagonal range of the candidate view (for example, 5 if minimum is 4 and maximum is 6) and the diagonal of the device where your application is running. Views with the lowest difference have a higher priority.

FireMonkey loads the first view of the list. If none of the views matches any of the requirements, FireMonkey loads the Master view instead.

You can find all the details about the RAD Studio built-in views in the platform-specific implementations of the System.Devices unit: System.Android.Devices.pas, System.Win.Devices.pas, and so on.

Form Names Are Different at Run Time

At run time, the Name property of the forms of your application may not match the names that you defined at design time. If FireMonkey loads a view other than Master, the names of the forms are the name that you gave the forms in the Master view plus the code name of the loaded view, joined by an underscore (_). For example, if the name of your form is "MyForm" and FireMonkey loads the "Windows Desktop" view at run time, the runtime name of your form is "MyForm_Windows".

Topics

See Also