Re: [twsocket] What is wrong in this code?
Hi Wilfried, I've already done this. Thank you and Francois and Dod for the responses. Have fun. /Ionut Wilfried Mestdagh wrote: > Hello Ionut, > > Change it like this: > > in the main function: > . > Rec := PrepareRec(true); > Rec.AllDist := Rec.AllDist - Dist; > Rec.count := RecCount; > Send(@Rec, SizeOf(TRec)); > Query.Next; > . > > in OnDataSent: > . >if not Query.Eof then begin > Rec := PrepareRec(true); > Rec.AllDist := Rec.AllDist - Dist; > Rec.count := RecCount; > Send(@Rec, SizeOf(TRec)); > Query.Next; >end; > . > > --- > Rgds, Wilfried [TeamICS] > http://www.overbyte.be/eng/overbyte/teamics.html > http://www.mestdagh.biz > > Monday, February 6, 2006, 11:26, Ionut Muntean wrote: > > >>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
Re: [twsocket] What is wrong in this code?
Hello Ionut, Change it like this: in the main function: . Rec := PrepareRec(true); Rec.AllDist := Rec.AllDist - Dist; Rec.count := RecCount; Send(@Rec, SizeOf(TRec)); Query.Next; . in OnDataSent: . if not Query.Eof then begin Rec := PrepareRec(true); Rec.AllDist := Rec.AllDist - Dist; Rec.count := RecCount; Send(@Rec, SizeOf(TRec)); Query.Next; end; . --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Monday, February 6, 2006, 11:26, Ionut Muntean wrote: > 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
Re: [twsocket] What is wrong in this code?
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" 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
Re: [twsocket] What is wrong in this code?
Don't use repeat/until ProcessMessage loop, you don't need it if you manage sending records thru OnDataSent. IM> Hi Wilfried, IM> I've changed the code to this: IM> in tha main function: IM> . IM> Rec := PrepareRec(true); IM> Rec.AllDist := Rec.AllDist - Dist; IM> Rec.count := RecCount; IM> Send(@Rec, SizeOf(TRec)); IM> Query.Next; IM> repeat IM> ProcessMessages IM> until SentOk; IM> . -- 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
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
Re: [twsocket] What is wrong in this code?
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
Re: [twsocket] What is wrong in this code?
Thanks Dod for your quick response. In OnClientDataAvailable there is a basic command parser, that receives data from the peer ... / Ionut Muntean Dod wrote: > Don't know but did you "Receive" data before ProcessMessage ? > > OnDataAvailable will be triggered until you read received data. > > Other thing, you should not do such repeat/until upon Send but better > use OnDataSent event to manage sending next record(s). > > IM> Hi, > IM> Please look at the code below. > IM> . > IM> . > IM> . > IM> try > IM>try > IM> Query.Open; > IM> OnDataSent := DataWasSent; > IM> // DataWasSent sets "SentOk" to True > IM> while not Query.EOF do > IM> begin > IM> Rec:= PrepareRec(true); > IM> Rec.AllDist := Rec.AllDist - D; > IM> Rec.Count := RecCount; > IM> SentOk := false; > IM> Send(@Rec, SizeOf(TRec)); > IM> repeat > IM> ProcessMessages; > IM> until SentOk; > IM> Query.Next; > IM> end; > IM>except > IM> on E: Exception do > IM> Display(ExecuteCommand1 - %s', [E.Message]); > IM>end > IM> finally > IM>Query.Close; > IM>OnDataSent := nil > IM> end; > > IM> The code is executed from OnClientDataAvailable of an TWSocketServer. > IM> When the execution reach the "repeat .. until SentOk", on > IM> ProcessMessages the code is reentered a second time. > > IM> What am I doing wrong? > > IM> 10x, > IM> 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
Re: [twsocket] What is wrong in this code?
Don't know but did you "Receive" data before ProcessMessage ? OnDataAvailable will be triggered until you read received data. Other thing, you should not do such repeat/until upon Send but better use OnDataSent event to manage sending next record(s). IM> Hi, IM> Please look at the code below. IM> . IM> . IM> . IM> try IM>try IM> Query.Open; IM> OnDataSent := DataWasSent; IM> // DataWasSent sets "SentOk" to True IM> while not Query.EOF do IM> begin IM> Rec:= PrepareRec(true); IM> Rec.AllDist := Rec.AllDist - D; IM> Rec.Count := RecCount; IM> SentOk := false; IM> Send(@Rec, SizeOf(TRec)); IM> repeat IM> ProcessMessages; IM> until SentOk; IM> Query.Next; IM> end; IM>except IM> on E: Exception do IM> Display(ExecuteCommand1 - %s', [E.Message]); IM>end IM> finally IM>Query.Close; IM>OnDataSent := nil IM> end; IM> The code is executed from OnClientDataAvailable of an TWSocketServer. IM> When the execution reach the "repeat .. until SentOk", on IM> ProcessMessages the code is reentered a second time. IM> What am I doing wrong? IM> 10x, IM> 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
[twsocket] What is wrong in this code?
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