'Delphi Firemonkey - loading style at runtime

I have loaded a couple of the sample styles from ......\RAD Studio\9.0\Styles as resources into my project and am 'simply' trying to load one of them at runtime.

I'm using the following code to try and do this:

var
  vResourceStream : TResourceStream;
begin

  vResourceStream := TResourceStream.Create( HInstance, 'DARKSTYLE', RT_RCDATA );

  try
    StyleBook1.LoadFromStream( vResourceStream );
  finally
    vResourceStream.Free;
  end;

It compiles ok but when I run it I get a bunch of errors, the first being 'Property Align does not exist' then 'Error reading TStyleBook.Align: Property Align does not exist' and it seems to do this for a bunch more atributes, Height etc.

Can someone give me some pointers as to how to solve it please?



Solution 1:[1]

Not that I know a bit about FMX, but AFAIU the .style files are resource definition files. Instead of reading the stylebook object from the stream, you should read its resource:

StyleBook1.Resource.LoadFromStream( vResourceStream );

Solution 2:[2]

For reference, there are LoadFromStream and LoadFromFile methods at TStyleBook, but there is also TStyleStreaming class with an extra LoadFromResource utility method (apart from its own LoadFromStream and LoadFromFile). Probably they should add a LoadFromStream to TStyleBook class too (guess it would call into the respective TStyleStreaming one)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 George Birbilis