Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TServiceApplication and Applicastion - All in on. 1

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi there.
How do I make a TServiceApplication to act as an application?

The background:
I have an existing project, which I want to modiify to a service. The twist is that I want it to be an application if I start it with the parameter /Application (or similar).
I also want to configure the service by starting it with the parameter /Config.

The problem is the unit SvcMgr which has to be in the uses clause. This unit changes the Application object I think...?

Code:
program ServiceApplication;

uses
  Forms,
  Dialogs,
  SysUtils,
  SvcMgr,
  ...
  ...
  ...
  Unit1 in 'Unit1.pas' {MainForm};

{$R *.RES}

begin
  Application.Initialize;
  if SameText(ParamStr(1), '/CONFIG') then
  begin
    // Start config
    Application.CreateForm(TConfigForm, ConfigForm);
  end else
  if SameText(ParamStr(1), '/APPLICATION') then
  begin
    // Start as application
    Application.CreateForm(TMainForm, MainForm);
  end else
    // Start as service
    Application.CreateForm(TRegenService, RegenService);
  Application.Run;
end.

I don't know how to explain my problem more than that.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
Damned.... Ignore the spelling issues.... I have a bad day today... ;-)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
here ya go :)

Code:
function HasParams : boolean;
begin
 Result:=ParamCount > 0;
end;

function ConfigApp : boolean;
begin
 Result:=HasParams;
 if Result then
  Result:=(FindCmdLineSwitch('config', ['-', '/'], True));
end;


begin
  if ConfigApp then
   begin
    Forms.Application.Initialize;
    Forms.Application.CreateForm(TFrm_config, Frm_config);
  Forms.Application.Run;
   end
  else
   begin
    SvcMgr.Application.Initialize;
    SvcMgr.Application.CreateForm(Tsvc_ipgsm, svc_ipgsm);
    SvcMgr.Application.Run;
   end;
end.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
If I then call for the Application variable when I'm running this as an application, which object do I call for? The TApplication or TServiceApplication?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
just use "unit".application where unit Svcmgr or forms depending on you want to activate the service or the application

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top