Search code examples
delphistylesruntimefiremonkey

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

  • 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 );