Delphi customized styles for us

If we do not want to use a built-in style, we can always use a custom style.
The Delphi installation comes with a number of custom styles. In Delphi 10.2
on Windows 10, FireMonkey custom styles are installed into the
C:\Users\Public\Documents\Embarcadero\Studio\19.0\Styles directory.
FireMonkey styles are files with the *.style extension. If we preview a
FireMonkey style file with a text viewer, we will see that its content looks
very much like a form file that we design with Form Designer inside the

It is good practice not to put non-visual components such as stylebooks
directly on the form, but on a dedicated data module instead. Select File |
New | Other from the main menu. In the New Items dialogs, select the Delphi
Files category and choose to add a new Data Module to the project:

This is how our form will look like after loading the Transparent style on
iOS and on Android. I really like it. It has a nice gradient and the controls
look a little like those on a space ship dashboard from science-fiction movies.
It is a good practice to put stylebook components on a dedicated data module.
In this way we could have multiple forms reusing the same styles.

Another option to load a custom style is to use the TStyleManager class
defined in the FMX.Styles unit. It has different public class methods for
loading styles from a file or from a resource. The advantage of this approach
is the fact that a style is loaded globally for the whole.

Transparent style added to the project as a resource
Click on OK to close the Resources dialog. The next step is to write code that
will read the custom style from the resource and set it as a style for the whole
application. Because this is global to all forms, a logical place to enter this
code is in the project file itself. Click on the View Source… in the Project
menu. Add to the project’s uses clause FMX.Styles and a call to the
TStyleManager class to try to load a custom style from the resource:

uFormStylesTest in 'uFormStylesTest.pas' {FormStylesTest},
uFormExtra in 'uFormExtra.pas' {FormExtra};
{$R *.res}
Application.CreateForm(TFormStylesTest, FormStylesTest);
Application.CreateForm(TFormExtra, FormExtra);

If we select the Edit Default Style… option we will be modifying the
default style used by all controls of a given type. The option to Edit Custom
Style… will only change the style for a given control, without changing the
style for all other controls.
Right-click on the ArcDial1 control and select Edit Custom Style… from
the context menu. This will open the FireMonkey Style Designer and in the
Structure View we can see the individual components that a
TArcDial control is made of. It feels very much like editing a form, but we
are editing a style here. The Object Inspector can be used to modify
properties of all sub-elements of a style and we can also modify them visually
in the designer.

Let’s change something to see the effect in the running app. Let’s change the
size and color of the indicator ellipse. Change its Width property to 30 and its
Height to 10. Now it is bigger. Expand its Brush property and change the
Color property to Cornflowerblue. Refer to the following screenshot:

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.