简体   繁体   中英

delphi xe6 firemonkey change form style runtime

hello how can i change (delphi firemonkey mobile application) stylebook runtime

i will try load from ini or text file when formcreate or formshow

but cannot work stylename is string

i was try this code but code1 work but code 2 cannot work

if RadioButton1.IsChecked then  Form1.StyleBook:=white else Form1.StyleBook:=black;

i need

form1.stylebook:= trim(Copy(Memo2.Lines.Strings[0],7,30)); {string ='black'}

but error code :[dcc32 Error] main.pas(226): E2010 Incompatible types: 'TStyleBook' and 'string'

To clear up some confussion:

  1. StyleBook property requires an object instance type of TStyleBook so your attempt to pass a string to that property will produce the Incompatible types error.

  2. StyleName is the name by which a style or style subcomponent is known for. I'm not exactly sure why you mentioned the StyleName property as it doesn't seem to have anything to do with your question.

To return to your question, how to load a style into a TStyleBook at runtime and apply it to the Form?

var
  aStyleBook : TStyleBook;
begin
  // Create styleBook and assign the main form as its owner
  aStyleBook := TStyleBook.Create(Self); 
  // Load style from file or Stream
  aStyleBook.Resource.LoadFromFile('...'); 
  // set the loaded style as active style
  Self.StyleBook := aStyleBook;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM