How to manually include VCL style in my application?

I have an application that uses conditional expressions to be able to compile it either as a VCL Forms application or as a Windows service application in Delphi XE2. However, since I manually modified the main project file, the IDE will no longer allow me to make certain changes using the standard Project Settings window. In particular, I cannot select VCL Styles for inclusion or implementation.

Therefore, I need to implement VCL Styles manually. So, I added the two necessary modules Vcl.Themes and Vcl.Styles to my project initialization block (which in this case does NOT match the main project block) and essentially copied the code from the working application to this new application.

Here is the main block of the project:

 program MyServiceApplication; uses uMyService in 'uMyService.pas' {MyService: TService}, uMyServiceMain in 'uMyServiceMain.pas', uMyServiceInit in 'uMyServiceInit.pas', uMyServiceTest in 'uMyServiceTest.pas' {frmMyServiceTest}; {$R *.RES} begin RunMyService; end. 

And then in the project initialization block:

 unit uMyServiceInit; interface uses {$IFDEF TESTAPP} Vcl.Forms, Vcl.Themes, Vcl.Styles, uMyServiceTest, {$ELSE} Vcl.SvcMgr, uMyService, {$ENDIF TESTAPP} uMyServiceMain ; procedure RunMyService; implementation procedure RunMyService; begin {$IFDEF TESTAPP} Application.Initialize; Application.MainFormOnTaskbar := True; TStyleManager.TrySetStyle('Carbon'); //<--- WILL NOT RUN - STYLE DOES NOT EXIST Application.Title := 'My Windows Service Application'; Application.CreateForm(TfrmMyServiceTest, frmMyServiceTest); {$ELSE} if not Application.DelayInitialize or Application.Installing then Application.Initialize; Application.CreateForm(TMyService, MyService); {$ENDIF TESTAPP} Application.Run; end; end. 

The problem is that when I start the application, I get the error Style 'Carbon' could not be found. simply because this style was not included and compiled into the application.

How can I compile this style manually in this application so that VCL styles can implement it?

PS: The reason that initialization is in a separate module is because if the conventions were implemented inside the main block of the application, the IDE would destroy the code.

EDIT

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

+4
source share
1 answer

TStyleManager loads available styles from the VCLSTYLE resource section of the executable file (unless you set TStyleManager.AutoDiscoverStyleResources to false). A resource is what is missing from your scenario. Basically, there are three ways to add your style as a resource in exe.

  • In the menu "Project" → "Resources and images ..". Add a style by clicking the "Add" button in the dialog box, set its type to "VCLSTYLE" and the identifier "CARBON".

  • Like Ken mentioned in a comment on a question through a .rc file. This is a text file that can contain a style string (and / or other resources). how

     CARBON VCLSTYLE "C:\..\RAD Studio\9.0\Redist\Styles\Vcl\Carbon.vsf" > 
    ( , ). "styles.rc", ( brcc32.exe bin, .res), {$R styles.res} .
  • As RRUZ said in his answer , which he linked in the commentary to the question by editing the .dproj file. Under the <PropertyGroup Condition="'$(Base)'!=''"> VCL_Custom_Styles add the 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> > 

+11
source

Source: https://habr.com/ru/post/1436030/


All Articles