Take the 2-minute tour ×

I have an application which uses conditionals to be able to compile it either as a VCL Forms Application or as a Windows Service Application in Delphi XE2. However, since I have manually altered the project's main source file, the IDE will no longer allow me to make certain modifications using the standard Project Options window. Specifically, I am not able to select VCL Styles to include or implement.

Therefore, I have to implement VCL Styles manually. So, I added the two necessary units Vcl.Themes and Vcl.Styles to my project's initialization unit (which in this case is NOT the same as the project's main unit), and essentially copied the code from a working application into this new application.

Here's the project's main unit:

program MyServiceApplication;

  uMyService in 'uMyService.pas' {MyService: TService},
  uMyServiceMain in 'uMyServiceMain.pas',
  uMyServiceInit in 'uMyServiceInit.pas',
  uMyServiceTest in 'uMyServiceTest.pas' {frmMyServiceTest};

{$R *.RES}


And then in the project's initialization unit:

unit uMyServiceInit;



procedure RunMyService;


procedure RunMyService;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Carbon'); //<--- WILL NOT RUN - STYLE DOES NOT EXIST
  Application.Title := 'My Windows Service Application';
  Application.CreateForm(TfrmMyServiceTest, frmMyServiceTest);
  if not Application.DelayInitialize or Application.Installing then
  Application.CreateForm(TMyService, MyService);


The trouble is, when the application runs, I get an error Style 'Carbon' could not be found. simply because this style has not been included and compiled into the application.

How can I compile this style manually into this application so that the VCL Styles can implement it?

PS: The reason why the initialization is in a separate unit is because if the conditionals were implemented inside the application's main unit, the IDE would destroy the code.


One thing I have tried: I opened a working project's .dproj file and searched for this style carbon hoping to find some configuration for it there, since the working project used this style, but with no luck. The word does not exist anywhere in that file.

share|improve this question
From a quick check with Resource Editor, it appears that the styles are added to a resource as VCLSTYLE resource type. This seems to imply you could create a standard .rc file with a list of the style files (the .vsf files from the $(BDS)\Redist\Styles\Vcl folder). I haven't had a chance to test it yet, though. You may also have to register the styles with the style manager in code as well. –  Ken White Sep 25 '12 at 0:15
Alternatively, you can use project->resources&images to add carbon.vsf with ID=CARBON, type=VCLSTYLE. –  Sertac Akyuz Sep 25 '12 at 0:27
Eureka, thanks @Sertac, that's the best solution I think. –  Jerry Dodge Sep 25 '12 at 0:30
Jerry, @Ken's method should also work, the only difference is that you add some 'some.rc' file to the project with project manager and then add a line {$R some.res}. –  Sertac Akyuz Sep 25 '12 at 0:46
@JerryDodge, this answer shows how add vcl styles manually using the Resource dialog or editing the .dproj file –  RRUZ Sep 25 '12 at 0:55
add comment

1 Answer

up vote 5 down vote accepted

TStyleManager is loading available styles from a 'VCLSTYLES' resource section of the executable (unless you set TStyleManager.AutoDiscoverStyleResources to false). The resource is what's missing in your scenario. Basically, there are three ways to add your style as a resource in the exe.

  • Through the 'Project' -> 'Resources and Images..' menu. Add the style clicking the 'Add' button in the dialog, set its type to 'VCLSTYLES' and identifier to 'CARBON'.

  • As Ken mentioned in the comment to the question, through an .rc file. This is a text file which can contain a line per style (and/or other resources). Like

    CARBON VCLSTYLE "C:\..\RAD Studio\9.0\Redist\Styles\Vcl\Carbon.vsf"
    (you can use relative paths if it is feasible). Let's name the file 'styles.rc', add the file to the project through project manager (or use brcc32.exe in the bin folder to compile it to a .res file) and then add a {$R styles.res} line to your unit.

  • As RRUZ told in his answer that he linked in a comment to the question, by editing the .dproj file. Under the <PropertyGroup Condition="'$(Base)'!=''"> key, add a VCL_Custom_Styles entry (his example includes several 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>

share|improve this answer
+1. Nice answer, Sertac. (And you even got a "Thank you" from Jerry in the comemnts, too. More than I got. ;-) –  Ken White Sep 25 '12 at 1:39
I actually prefer it, because it makes it much easier to add/remove things like styles (if you can't do it using Project->Options). It's really easy to open the text .rc file and comment out or add a line, save, and then build the project to make the changes take effect. It's quicker than using the resource dialog. :-) –  Ken White Sep 25 '12 at 1:53
I've written plenty of .rc files but I never realized there was a quick menu item to add resources. –  Jerry Dodge Sep 25 '12 at 2:35
add comment

Your Answer


