7

How do I embed Delphi XE2 VCL-Styles in a dll? The Application - Appearance page is not visible in project settings for DLL-projects.

I tried defining them in a rc-file included with a $R directive which works but if there is a better way I'd like to know.

RC-file example:

GOLDENGRAPHITE VCLSTYLE "C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\Redist\styles\vcl\GoldenGraphite.vsf"
CARBON VCLSTYLE "C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\Redist\styles\vcl\Carbon.vsf"

In particular having to specify the full path to XE2-installation folder is something I want to avoid.

Ville Krumlinde
  • 7,021
  • 1
  • 33
  • 41
  • 1
    You could do the same using Project Resource dialog. Also, RC is happy with relative paths. – OnTheFly Mar 14 '12 at 14:05
  • Also be aware that you will need to disable system hooks in a DLL as there is no Mainform, otherwise you'll get Access Violations: TStyleManager.SystemHooks := []; TStyleManager.TrySetStyle(StyleName); – SoftDeveloper Jun 07 '23 at 10:33

3 Answers3

10

Another options which you can use

1) Using the Resource dialog.

enter image description here

2) Editing the dproj file of your dll

under this key <PropertyGroup Condition="'$(Base)'!=''">

Add one Entry VCL_Custom_Styles for the vcl styles

<VCL_Custom_Styles>&quot;Amakrits|VCLSTYLE|$(PUBLIC)\Documents\RAD Studio\9.0\Styles\Amakrits.vsf&quot;;&quot;Amethyst Kamri|VCLSTYLE|$(PUBLIC)\Documents\RAD Studio\9.0\Styles\AmethystKamri.vsf&quot;;&quot;Aqua Graphite|VCLSTYLE|$(PUBLIC)\Documents\RAD Studio\9.0\Styles\AquaGraphite.vsf&quot;</VCL_Custom_Styles>
RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Thanks, never noticed the resource dialog before. Both suggestions are good. – Ville Krumlinde Mar 14 '12 at 21:15
  • I've added the resource, it's in my cbproj as: ResourceItem VCLSTYLE AMAKRITS Now how to access it dynamically? I tried TStyleManager::SetStyle but it throws an exception that the style cannot be found. Do I need to do anything else? – Bizmarck Feb 23 '16 at 19:06
1

It works for us also (thanks Rodrigo). Just a couple of details

  • Don't expect to find the VCLSTYLE on the list of the Resource Type Combo Box, you have to type it manually.

  • Don't miss to initialize the style in your DLL, we add the next code to the FormCreate event: TStyleManager.SetStyle('Carbon');

0

To access correctly to the Style added as a resource check you are adding to the uses clause both units: Vcl.Themes, Vcl.Styles.