Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Threads and Sessions.
| Subject: | Re: Threads and Sessions. |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Thu, 31 Aug 2006 11:08:47 |
"Massimo Bolzoni" <massimo.bolzoni@mandelli.com> wrote in message
news:44f6dc5c$1@newsgroups.borland.com...
> I don't understand what "OnExecute is triggered in a loop" means.
I meant exactly what I said. Inside of TIdTCPServer, the thread that
manages a client connection is continuously triggering the OnExecute event
handler inside a loop for the lifetime of the connection.
> If I create the DataModule instance in the OnConnect event,
> how can I retrieve the reference to it in the OnExecute?
You can store the DataModule pointer into the TIdContext.Data property. For
example:
procedure TForm1.IdTCPServerConnect(AContext: TIdContext);
begin
AContext.Data := TMyDataModule.Create(nil);
end;
procedure TForm1.IdTCPServerExecute(AContext: TIdContext);
var
DM: TMyDataModule;
begin
DM := TMyDataModule(AContext.Data);
// use DM as needed ...
end;
procedure TForm1.IdTCPServerDisconnect(AContext: TIdContext);
begin
AContext.Data.Free;
AContext.Data := nil;
end;
> Many clients can connect to the server simultaneously!
All the more reason not to bog the server down with repeatedly
opening/closing database connections for each individual client all the
time.
Gambit