Delphi XE2: reloading VCL custom style from file?

I am loading a custom style from a file using:

TStyleManager.LoadFromFile(filename) 

When the file is modified, I want to download it again. But if I try, I get an EDuplicateStyleException because the style is already registered.

Is there a way to unload a style in order to reload it? A typical example of this is that you make custom style changes and want to see it in action without restarting the entire application.

+7
source share
4 answers

After scanning the sources, I think this is not possible in the direct path. The only chance is to implement a dirty hack.

Whatever you do, you should write a QC for this. Embarcadero can implement a file reload if the style already exists, and not to throw an exception. It would look like a natural behavior to me.

+6
source

Check out this vcl styles utils project, one of the public functions is the ability to unload the vcl style. Just include the Vcl.Styles.Ext project in the project, and then use this code.

  TStyleManager.RemoveStyle('Carbon'); 
+3
source

Another idea: It might work. Partial code for simplicity. In the code below, you will first get a handle to an already registered style. I assume that you can delete and reassign the pointer from the one you loaded from the file. I believe that an exception is shown only when trying to apply a style, and not when loading it. Forgive me if I am wrong.

 var StyleName: String; Style : TStyleManager.TStyleServicesHandle; FileName : String; begin StyleName := 'Obsidian'; // or another style name FileName := 'obsidian.vsf'; // or any other valid style file name Style := TStyleManager.Style[ StyleName]; if Assigned( Style) then // style already registered begin TStyleManager.TrySetStyle( StyleName); // insert other processing here end else // style not registered begin if TStyleManager.IsValidStyle( FileName) then begin Style := TStyleManager.LoadFromFile( FileName); if Assigned( Style) then begin // insert other processing here, such as // TStyleManager.SetStyle( Style); end; end; end; end; 
+2
source

You can make a copy of each style in another file with a different style name. Then you can download it as a workaround. If you really need the original, you can download it after downloading the copy.

0
source

All Articles