Re: Events in a console app
- From: "JamesR" <wizzer90@xxxxxxxxxxx>
- Date: 26 Aug 2006 11:35:52 -0700
OK thanks Rob.
I know these components were downgraded apparently by Borland -
removing them from initial component palette, but they seem to work as
far as I can see (winderng why they did this). Being non-blocking
aswell rather than the blocking of Indy, they simplify things a bit
too.
If I have to come up with a message loop now btw, then now I have to
decide whether creating a blank form server rather than a console would
make much difference as far as resources used etc, rather than just a
few more KB memory space.
James.
Rob Kennedy wrote:
JamesR wrote:
I've tried using a TDataModule with a TServerSocket in a console app,
but for instance OnClientConnect never fires, although the client can
actually connect to the thread. I think it must work a differen't way
in console apps - no windows messages of course, so when I have my
console app waiting on a ReadLn() in the main program, perhaps no
events get fired.
Yep. Those events get fired in response to messages arriving at your
program's window. But your program doesn't have a window, so no messages
get handled.
Infact, i've also tried creating the TServerSocket in a TThread, which
again will allow a connection, but the events don't fire.
And again that's because there's nothing processing any messages.
Do I need to poll for these events. I would presume that TServerSocket
for example would have some internal notification of when the client
connects and call this event.
It does have an internal notification, but it relies on receiving a
message from the OS. A message loop is fairly easy to write. The basic
structure goes like this:
while GetMessage(...) > 0 do begin
TranslateMessage(...);
DispatchMessage(...);
end;
Look in MSDN for details on the parameters.
You might also consider using Indy, which does all its own listening and
notification.
--
Rob
.
- References:
- Events in a console app
- From: JamesR
- Re: Events in a console app
- From: Rob Kennedy
- Events in a console app
- Prev by Date: Re: Events in a console app
- Next by Date: Re: MessageDlg jams screen update
- Previous by thread: Re: Events in a console app
- Index(es):
Relevant Pages
|