How to change a Firemonkey style at runtime and save it to file?


How to change a Firemonkey style at runtime and save it to file?

https://drive.google.com/file/d/0BwdfodaqQm4pYlotQWEySC0tOTA/view?usp=sharing

I want to change the style of this TPathLabel at runtime, and then save it to file.

I try to use:
(PathLabel2.FindStyleResource('text') as TText).TextSettings.FontColor :=
$FF18B3EC;

The style doesn't change.


When I clone the style, and set a new StyleName, then change StyleLookUp property of TPathLabel to this StyleName, it works. But what I want is not create a new style but change the current.

Comments

  1. Chang Guangyu Here are a couple of things to notes that might help:
    1. It is advisable to modify the style at run-time in the ApplyStyleLookup event

    2. If you try to modify it outside this event, try calling PathLabel2.ApplyStyleLookup before accessing the resource. This (in theory) will make sure the component loads the style

    3. The typical way to do what you write is:
    tmpObj:=PathLabel2.FindStyleResource('text');
    if assigned(tmpObj) then
    begin
    (tmpObj as TText).....
    ...
    end;

    I haven't tested the above; hope the code works

    ReplyDelete
  2. John Kouraklis Thank you. The first way works, but I want change the style in stylebook at runtime, then apply it to control, and then save the stylebook to file. The 3rd way doestn't work, setting (tmpObj as TText).FontColor will not change the color of PathLabel2.
    And how to "call PathLabel2.ApplyStyleLookup before accessing the resource" ?

    ReplyDelete

Post a Comment