Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-11 Thread Arno Garrels
Arne Fl. Jensen wrote:
 And both fail, with the same error in clientConnect and
 clientDisConnect, and postmessage.
 
 In your examples, there is no postMessage or postthreadMessage.
 Are there any examples of this, in a formless app.?

Now there is one:

{code}
program Project1;

{ This demo shows how to register and use custom messages posted to }
{ the ICSv7 hidden window.  }

{$APPTYPE CONSOLE}

{$DEFINE NOFORMS} // Do not include unit Forms.pas

uses
  Windows, Messages, SysUtils, Classes,
  OverbyteIcsWndControl,
  OverbyteIcsHttpSrv;

type
  TMyHttpServer = class(THttpServer)
  private
FMsg_WM_MYMESSAGE: UINT;
FOnMyMessage: TNotifyEvent;
  protected
procedure AllocateMsgHandlers; override;
procedure FreeMsgHandlers;  override;
function  MsgHandlersCount: Integer;  override;
procedure WndProc(var MsgRec: TMessage);  override;
  public
constructor Create(AOwner: TComponent); override;
procedure PostMyMessage;
property OnMyMessage: TNotifyEvent read FOnMyMessage write FOnMyMessage;
  end;

  TApp = class
  private
FMyHttpServer : TMyHttpServer;
procedure MyHttpServerMyMessage(Sender: TObject);
  public
procedure Run;
  end;

constructor TMyHttpServer.Create(AOwner: TComponent);
begin
inherited;
{ Make sure the internal window is created early otherwise our  }
{ overridden message registration methods were called too late. }
AllocateHWnd;
end;

function TMyHttpServer.MsgHandlersCount : Integer;
begin
Result := 1 + inherited MsgHandlersCount;
end;

procedure TMyHttpServer.AllocateMsgHandlers;
begin
inherited AllocateMsgHandlers;
FMsg_WM_MYMESSAGE := FWndHandler.AllocateMsgHandler(Self);
end;

procedure TMyHttpServer.FreeMsgHandlers;
begin
if Assigned(FWndHandler) then
FWndHandler.UnregisterMessage(FMsg_WM_MYMESSAGE);
inherited FreeMsgHandlers;
end;

{ Message handler }
procedure TMyHttpServer.WndProc(var MsgRec: TMessage);
begin
with MsgRec do
begin
if Msg = FMsg_WM_MYMESSAGE then
begin
try
if Assigned(FOnMyMessage) then
FOnMyMessage(Self);
except
on E: Exception do
HandleBackGroundException(E);
end;
end
else
inherited WndProc(MsgRec);
end;
end;

procedure TMyHttpServer.PostMyMessage;
begin
PostMessage(Handle, FMsg_WM_MYMESSAGE, 0, 0);
end;

{ TApp }

procedure TApp.MyHttpServerMyMessage(Sender: TObject);
begin
WriteLn('My message received');
{ In current ICSv7 call method PostQuitMessage to break the message loop }
FMyHttpServer.PostQuitMessage;
{ In older versions you have to post message WM_QUIT yourself }
//PostMessage(FMyHttpServer.Handle, WM_QUIT, 0, 0);
end;

procedure TApp.Run;
begin
FMyHttpServer := TMyHttpServer.Create(nil);
try
FMyHttpServer.OnMyMessage := MyHttpServerMyMessage;
FMyHttpServer.PostMyMessage;
{ Start the built-in message pump }
FMyHttpServer.MessageLoop;
finally
FMyHttpServer.Free;
end;
end;

var
App: TApp;
begin
try
App := TApp.Create;
try
App.Run;
finally
App.Free;
end;
WriteLn('Press Enter to exit');
ReadLn;
except
on E: Exception do
begin
WriteLn(E.ClassName + ' ' + E.Message);
WriteLn('Press Enter to exit');
ReadLn;
end;
end;
end.
{code}

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


Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-10 Thread Francois PIETTE
You should have started from OverbyteIcsSvcTcp which is a service instead 
of a GUI application.



I did originally but went to the console-app, since it is easier to debug.
As I understand it, it's the same unit used in both situations ..


As you know how to change from one application type to another type, then it 
is OK. I have designed the demos to use the same module for the core 
function to illustrate how this can be done.


--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

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


Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-10 Thread Arne Fl. Jensen
I did originally but went to the console-app, since it is easier to debug.
As I understand it, it's the same unit used in both situations ..

/arne

2010/11/9 Francois PIETTE francois.pie...@skynet.be

 I try to create a windows service with Httpserver. I have used the example
 in the OverbyteIcsSrvTcp1 project, with a separate unit OverbyteIcsCmd.

 You should have started from OverbyteIcsSvcTcp which is a service instead of 
 a GUI application.
 Warning: the two demo names are very similar.

 --
 francois.pie...@overbyte.be
 The author of the freeware multi-tier middleware MidWare
 The author of the freeware Internet Component Suite (ICS)
 http://www.overbyte.be

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


Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-10 Thread Arne Fl. Jensen
And both fail, with the same error in clientConnect and
clientDisConnect, and postmessage.

In your examples, there is no postMessage or postthreadMessage.
Are there any examples of this, in a formless app.?


2010/11/10 Francois PIETTE francois.pie...@skynet.be:
 You should have started from OverbyteIcsSvcTcp which is a service instead
 of a GUI application.

 I did originally but went to the console-app, since it is easier to debug.
 As I understand it, it's the same unit used in both situations ..

 As you know how to change from one application type to another type, then it
 is OK. I have designed the demos to use the same module for the core
 function to illustrate how this can be done.

 --
 francois.pie...@overbyte.be
 The author of the freeware multi-tier middleware MidWare
 The author of the freeware Internet Component Suite (ICS)
 http://www.overbyte.be

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

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


Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-09 Thread Arno Garrels
Arne Fl. Jensen wrote:
 Hi all,
 
 
 I try to create a windows service with Httpserver. I have used the
 example in the OverbyteIcsSrvTcp1 project, with a separate unit
 OverbyteIcsCmd. In the last mentioned - in my version I use
 Thttpserver.  Here are two events; ClientConnect and ClientDisConnect
 witch use postmessage (Handle, WM_CLIENT_COUNT, 0, 0). I have a
 messagepump like this: 

You do not need a message pump in TService, both main and service
thread process messages. If you drop the component on the TService
data module server events trigger in main thread, if you create
the component in i.e. OnServiceStart  at run-time events are triggered
in the service thread. The WM_CLIENT_COUNT message is a custom
message declared in the demo and sent to mainform's window handle.

Since there are no windows in a TService application but the hidden
ICS window(s) by default you have to either register your custom
message in a derived THttpServer class and override its WndProc method
and the post the custom message to server's window handle or you create
your own hidden window (see Classes.AllocateHWnd) and use that as the
destination window.

My enhanced service framework DDService might help you as it has a 
property that creates a hidden window in the service thread. It also
allows to use custom service controls which are simply windows
messages posted to the service thread. Something like:
PostThreadMessage(ServiceThreadID, CM_SERVICE_CONTROL_CODE, 
user-defined control code in the range 128 to 255, a LParam).
would trigger event OnCustomControl.

http://www.duodata.de/misc/delphi/DDService.zip

 
-- 
Arno Garrels


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


Re: [twsocket] HttpServer - PostMessage in a service/Cmd apps.

2010-11-09 Thread Francois PIETTE

I try to create a windows service with Httpserver. I have used the example
in the OverbyteIcsSrvTcp1 project, with a separate unit OverbyteIcsCmd.


You should have started from OverbyteIcsSvcTcp which is a service instead of 
a GUI application.

Warning: the two demo names are very similar.

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be

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