An Unexpected FileName

Recently, I encountered an unusual FireMonkey error on Linux where the application failed while creating a DataModule containing a TStyleBook. I'm not sure if it was my fault, or a serialization issue.

The exception referred to a file named MBPStyleBook in the PA Server deployment directory.

This was unexpected because MBPStyleBook was the name of the TStyleBook component, not a file.

Inspecting the DataModule's .fmx file revealed the cause. The TStyleBook contained the following property:

object MBPStyleBook: TStyleBook
    FileName = 'MBPStyleBook'
    ...
end

The FileName property tells the TStyleBook that an external style file is associated with it. Because the value contained only the component name, FireMonkey treated MBPStyleBook as a relative filename and attempted to access it from the application's deployment directory.

In this case, the style data was already embedded in the TStyleBook, so the FileName property was unnecessary. Removing it from the .fmx file fixed the problem:

object MBPStyleBook: TStyleBook
    ...
end

If the TStyleBook has a property named ResourcesBin, leave that intact, as it contains the embedded style data.

To make the change, view the DataModule as text, remove only the unexpected FileName property, switch back to the form designer, and rebuild the project.