Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:08:11+00:00 2026-05-23T14:08:11+00:00

Has anyone ever tried to attach delphi to his own windows service(32 bit app.)

  • 0

Has anyone ever tried to attach delphi to his own windows service(32 bit app.) process under Windows Server 2008 64 bit?

When I try to do this I get the error:
Unable to create the process. The parameter is incorrect.

if anyone of you know how to do this, that help would be really appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:08:11+00:00Added an answer on May 23, 2026 at 2:08 pm

    Whilst you can debug a Delphi service there are a number of hoops that you need to jump through to make it work. I never bother and simply ensure that my services can run either as a service or as a standard app. When I want to debug I run as a standard app and so sidestep all the headaches.

    I’ve hacked out all the code into a single file for the purpose of this answer, but you’d want to structure it a bit differently.

    program MyService;
    
    uses
      SysUtils, Classes, Windows, Forms, SvcMgr;
    
    type
      TMyService = class(TService)
      private
        procedure ServiceStart(Sender: TService; var Started: Boolean);
        procedure ServiceStop(Sender: TService; var Stopped: Boolean);
        procedure ServicePause(Sender: TService; var Paused: Boolean);
        procedure ServiceExecute(Sender: TService);
        procedure ServiceContinue(Sender: TService; var Continued: Boolean);
      protected
        FDescription: string;
        FEventLogSourceName: string;
        procedure Initialise; virtual; abstract;
        class function CreateRunner: TObject; virtual; abstract;
      public
        constructor Create(AOwner: TComponent); override;
        function GetServiceController: TServiceController; override;
      end;
      TMyServiceClass = class of TMyService;
    
    { TMyService }
    
    constructor TMyService.Create(AOwner: TComponent);
    begin
      inherited;
      Initialise;
      OnStart := ServiceStart;
      OnStop := ServiceStop;
      OnPause := ServicePause;
      OnExecute := ServiceExecute;
      OnContinue := ServiceContinue;
    end;
    
    procedure TMyService.ServiceStart(Sender: TService; var Started: Boolean);
    begin
      Started := True;
    end;
    
    procedure TMyService.ServiceStop(Sender: TService; var Stopped: Boolean);
    begin
      Stopped := True;
    end;
    
    procedure TMyService.ServiceContinue(Sender: TService; var Continued: Boolean);
    begin
      ServiceStart(Sender, Continued);
    end;
    
    procedure TMyService.ServicePause(Sender: TService; var Paused: Boolean);
    begin
      ServiceStop(Sender, Paused);
    end;
    
    procedure TMyService.ServiceExecute(Sender: TService);
    var
      Runner: TObject;
    begin
      Runner := CreateRunner;
      Try
        while not Terminated do begin
          ServiceThread.ProcessRequests(True);
        end;
      Finally
        FreeAndNil(Runner);
      End;
    end;
    
    var
      Service: TMyService;
    
    procedure ServiceController(CtrlCode: DWORD); stdcall;
    begin
      Service.Controller(CtrlCode);
    end;
    
    function TMyService.GetServiceController: TServiceController;
    begin
      Result := ServiceController;
    end;
    
    procedure RunAsService(ServiceClass: TMyServiceClass; var Service);
    var
      Application: TServiceApplication;
    begin
      Application := SvcMgr.Application;
      Application.Initialize;
      Application.CreateForm(ServiceClass, Service);
      Application.Run;
    end;
    
    procedure RunAsStandardExecutable(ServiceClass: TMyServiceClass);
    var
      Application: TApplication;
      Runner: TObject;
    begin
      Application := Forms.Application;
      Application.Initialize;
      Runner := ServiceClass.CreateRunner;
      Try
        while True do begin
          Try
            Application.HandleMessage;
          Except
            Application.HandleException(Application);
          End;
        end;
      Finally
        FreeAndNil(Runner);
      End;
    end;
    
    procedure ServiceMain(ServiceClass: TMyServiceClass);
    begin
      if FindCmdLineSwitch('RunAsApp', ['-', '/'], True) then begin
        RunAsStandardExecutable(ServiceClass);
      end else begin
        RunAsService(ServiceClass, Service);
      end;
    end;
    
    begin
      ServiceMain(TMyService);
    end.
    

    To use this you need to create a new class, inherited from TMyService, and implement Initialise and CreateRunner. CreateRunner is the key. In my services this creates an object which in turn opens a listening socket ready for clients to communicate over.

    The standard app code is pretty basic. It doesn’t even have a mechanism to terminate—it runs inside a while True loop. That doesn’t matter for my debugging needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone ever tried sending emails using 1&1 smtp host? I tried the following?
Has anyone ever tried to use custom binding with SSL in a WCF web
Has anyone ever tried making the drop-downs appear like a carousel? I have a
Just wondering if anyone has ever tried to determine the actual size of a
Has anyone ever tried, or had any success at getting Wascana (Eclipse CDT +
has anyone ever tried to get the list of all the movieclips (even the
Has anyone ever tried to implement ICommandSource with VB? The examples provided by Microsoft
Has anyone ever tried to integrate AspDotNetStorefront and Sitecore? I've been trying for the
Has anyone ever tried parsing out phrasal verbs with Stanford NLP? The problem is
Has anyone one ever tried that ? EGOTableViewPullRefresh seems rely on the fact that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.