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;
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's initialization unit:
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 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.
EDIT
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.
Resource Editor
, it appears that the styles are added to a resource asVCLSTYLE
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.dproj
file – RRUZ