> The standard Borland service unit runs a perfectly normal application
> message pump, and you can drop event drive components like ICS, timers,
> etc, onto the form and they just work, and you can post message to the
> form handle.

How to post the message to what handle.
If you create a new service application, you can drop non-UI components on 
it.
I have tried posting a message (postmessage/ postThreadMessage) to the 
Service handle and servive threadid, but none of them seem to work
Am I missing something here ?

Paul


Main Service application unit :

type
  TRPPollSvc = class(TService)
    procedure ServiceExecute(Sender: TService);
    procedure ServiceStart(Sender: TService; var Started: boolean);
    procedure ServiceStop(Sender: TService; var Stopped: boolean);
    procedure ServiceDestroy(Sender: TObject);
    procedure ServiceCreate(Sender: TObject);
    procedure WMError(var message: TMessage); message WM_ERROR;
  private
    { Private declarations }
    PServer    : TPSvc;
    FLogfileName  : string;
    FLogInitiated : boolean;
    procedure Display(Msg: string);
  public
    function GetServiceController: TServiceController; override;
    { Public declarations }
  end;

var
  RPPollSvc: TRPPollSvc;

implementation

{$R *.DFM}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  RemotePassPollSvc.Controller(CtrlCode);
end;

function TRPPollSvc.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TRPPollSvc.ServiceExecute(Sender: TService);
begin
  while not terminated do ServiceThread.ProcessRequests(true);
end;

procedure TRPPollSvc.ServiceStart(Sender: TService; var Started: boolean);
begin
  // give handle to server object - it needs it to post a message to the 
service application
  PServer.MainHandle:= ServiceThread.ThreadID;// .Handle;
  if PServer.StartServer then Started:= true
    else Started:= false;
end;

procedure TRPPollSvc.ServiceStop(Sender: TService; var Stopped: boolean);
begin
  PServer.StopServer;
  Stopped:= true;
end;

procedure TRPPollSvc.ServiceDestroy(Sender: TObject);
begin
  if Assigned(PServer) then
    begin
      PServer.Free;
      PServer:= nil;
    end;
end;

procedure TRPPollSvc.ServiceCreate(Sender: TObject);
begin
  PServer:= TPSvc.Create;
  PServer.OnDisplay:= Display;
  FLogFileName:= ChangeFileExt(Application.ExeName, '.log');
end;

procedure TRPPollSvc.Display(Msg: string);
var
  lFile: TextFile;
begin
  AssignFile(lFile, FLogFileName);
  try
    try
      if not FileExists(FLogFileName) then ReWrite(lFile)
      else Append(lFile);
      if not FLogInitiated then  //just opened
        begin
          FLogInitiated:= true;
          WriteLn(lFile, Msg);
        end;
      Writeln(lFile, Msg);
    finally
      CloseFile(lFile);
    end;
  except
  end;
end;

procedure TRPPollSvc.WMError(var message: TMessage); //message WM_ERROR;
begin
  Display('Error');
end;

end.


>From a thread within the server object I've tried to post a message to the 
service handle/threadID
PostThreadMessage(MainHandle, WM_ERROR, 0, 0);


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to