You can't call the message pump (ProcessMessages or any other form of it) from 
an ICS event handler.
If you do, as you see, the events are reentered. This is not an ICS issue, this 
is always the case,
it is simply very visible with fast hardware triggered events such as netwrok 
events. A simple
TButton has exactly the same problem: If you call the messag epump from a 
TButton OnClick handler
and the user click again on the button, your event handler is re-entered 
causing lot of trouble in
your code.

Solution: Change your design !

--
Contribute to the SSL Effort. Visit
http://www.overbyte.be/eng/ssl.html
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be



----- Original Message ----- 
From: "Ionut Muntean" <[EMAIL PROTECTED]>
To: "ICS support mailing" <twsocket@elists.org>
Sent: Monday, February 06, 2006 11:26 AM
Subject: Re: [twsocket] What is wrong in this code?


> Hi Wilfried,
>
> I've changed the code to this:
>
> in tha main function:
> .....
>                 Rec := PrepareRec(true);
>                 Rec.AllDist := Rec.AllDist - Dist;
>                 Rec.count := RecCount;
>                 Send(@Rec, SizeOf(TRec));
>                 Query.Next;
>                 repeat
>                      ProcessMessages
>                 until SentOk;
> .....
>
> in OnDataSent:
> .....
>       if Query.Eof then
>       begin
>            SentOk := true;
>            exit;
>       end
>       else
>       begin
>            Rec := PrepareRec(true);
>            Rec.AllDist := Rec.AllDist - Dist;
>            Rec.count := RecCount;
>            Send(@Rec, SizeOf(TRec));
>            Query.Next;
>
>       end;
>
> The code is still entering 2 times ... :(
>
> / Ionut Muntean
>
>
> Wilfried Mestdagh wrote:
> > Hello Ionut,
> >
> >
> >>The code is executed from OnClientDataAvailable of an TWSocketServer.
> >>When the execution reach the "repeat .. until SentOk", on
> >>ProcessMessages the code is reentered a second time.
> >
> >
> > This is normal. When you start looping processmessages then your code
> > can be reentered because messages ar pumped. This is also bad design.
> > You can easy change your code event driven, just call Send there with
> > the first record. On OnDataSent you send your next record, etc, as Dod
> > already mentioned.
> >
> > ---
> > Rgds, Wilfried [TeamICS]
> > http://www.overbyte.be/eng/overbyte/teamics.html
> > http://www.mestdagh.biz
> >
> > Monday, February 6, 2006, 10:49, Ionut Muntean wrote:
> >
> >
> >>Hi,
> >>Please look at the code below.
> >>.
> >>.
> >>.
> >>      try
> >>           try
> >>                Query.Open;
> >>                OnDataSent := DataWasSent;
> >>                // DataWasSent sets "SentOk" to True
> >>                while not Query.EOF do
> >>                begin
> >>                     Rec    := PrepareRec(true);
> >>                     Rec.AllDist := Rec.AllDist - D;
> >>                     Rec.Count := RecCount;
> >>                     SentOk := false;
> >>                     Send(@Rec, SizeOf(TRec));
> >>                     repeat
> >>                          ProcessMessages;
> >>                     until SentOk;
> >>                     Query.Next;
> >>                end;
> >>           except
> >>                on E: Exception do
> >>                     Display(ExecuteCommand1 - %s', [E.Message]);
> >>           end
> >>      finally
> >>           Query.Close;
> >>           OnDataSent := nil
> >>      end;
> >
> >
> >>The code is executed from OnClientDataAvailable of an TWSocketServer.
> >>When the execution reach the "repeat .. until SentOk", on
> >>ProcessMessages the code is reentered a second time.
> >
> >
> >>What am I doing wrong?
> >
> >
> >>10x,
> >>Ionut Muntean
> >
> >
>
> -- 
> 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

-- 
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