I have a custom Delphi component created for Firemonkey (fmx). I now need to apply my custom style to the component. The style is saved in a resource. Previously this was done in the GetStyleObject method by calling TStyleManager.LoadFromResource.
This method (LoadFromResource) does not exist anymore in Delphi 10 Seattle for the Firemonkey framework.
My code in XE7 was working through the LoadFromResource:
function TFMXPic.GetStyleObject: TFmxObject;
var
style : string;
begin
if (StyleLookup = '') then
begin
style := GetClassStyleName;
Result := TControl(TStyleManager.LoadFromResource(HInstance,
style, RT_RCDATA));
Exit;
end;
Result := inherited GetStyleObject;
end;
How do I achieve this in Delphi 10 Seattle?
first, I don't think it is correct to check the StyleLookup. This property tells the component to look for this specific style name in the stylebook.
Then, you try to load a style file at component level. FMX does work like this. You have a style book, which loads the style file and then each component in a form uses this book to locate the style name as defined by the stylelookup value.
Out of my head, this course of actions should do the job:
Add the style file in the resources of your project as you have already done. Say you have a style called "mycomponent" for your component
Add a stylebook in the form
in the OnCreate even of the form, load the resource file to a TResourceStream and then load the last to the stylebook using TStyleBook.LoadFromStream
Now you can access the style by setting the StyleLookup='mycomponent' property of your component
Hope this helps.