Re: [twsocket] ICS Wnd Control - Possible bug
Eric, I guess it helps to remove all pending messages with the given ID from the queue when the message ID is unregistered. One could do that either in custom code or maybe it should be added in TIcsWndHandler.UnregisterMessage as below? procedure TIcsWndHandler.UnregisterMessage(var Msg: UINT); var LMsg: TMsg; // == added begin if Msg = 0 then Exit; if FMsgLow WM_USER then raise EIcsException.Create('MsgLow not defined'); if Msg = (FMsgLow + WH_MAX_MSG) then raise EIcsException.Create('Msg value out of bound'); if not Assigned(FMsgMap[Msg - FMsgLow]) then raise EIcsException.Create('Msg not registered'); FMsgMap[Msg - FMsgLow] := nil; Dec(FMsgCnt); Msg := 0; while PeekMessage(LMsg, FHandle, Msg, Msg, PM_REMOVE) do {loop}; // == added if FMsgCnt = 0 then DeallocateHWnd; end; -- 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] ICS Wnd Control - Possible bug
HI Arno True, I think that will help, I will add this line to my ICS code to check if it works, but I believe that it will work I also think that this is something that must be on ICS code, on UnregisterMessage as you proposed, not custom code. I will test and come back to you soon Eric -- From: Arno Garrels arno.garr...@gmx.de Sent: Wednesday, August 18, 2010 11:43 AM To: ICS support mailing twsocket@elists.org Subject: Re: [twsocket] ICS Wnd Control - Possible bug Eric, I guess it helps to remove all pending messages with the given ID from the queue when the message ID is unregistered. One could do that either in custom code or maybe it should be added in TIcsWndHandler.UnregisterMessage as below? procedure TIcsWndHandler.UnregisterMessage(var Msg: UINT); var LMsg: TMsg; // == added begin if Msg = 0 then Exit; if FMsgLow WM_USER then raise EIcsException.Create('MsgLow not defined'); if Msg = (FMsgLow + WH_MAX_MSG) then raise EIcsException.Create('Msg value out of bound'); if not Assigned(FMsgMap[Msg - FMsgLow]) then raise EIcsException.Create('Msg not registered'); FMsgMap[Msg - FMsgLow] := nil; Dec(FMsgCnt); Msg := 0; while PeekMessage(LMsg, FHandle, Msg, Msg, PM_REMOVE) do {loop}; // == added if FMsgCnt = 0 then DeallocateHWnd; end; -- 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 Nenhum virus encontrado nessa mensagem recebida. Verificado por AVG - www.avgbrasil.com.br Versao: 9.0.851 / Banco de dados de virus: 271.1.1/3079 - Data de Lancamento: 08/18/10 03:35:00 -- 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] ICS Wnd Control - Possible bug
Msg := 0; while PeekMessage(LMsg, FHandle, Msg, Msg, PM_REMOVE) do {loop}; // == added if FMsgCnt = 0 then DeallocateHWnd; end; Just a little correction while PeekMessage(LMsg, FHandle, Msg, Msg, PM_REMOVE) do {loop}; // == added Msg := 0; Or else you will pass 0 to PeekMessage Eric -- 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] ICS Wnd Control - Possible bug
Arno Garrels wrote: Eric, I guess it helps to remove all pending messages with the given ID from the queue when the message ID is unregistered. One could do that either in custom code or maybe it should be added in TIcsWndHandler.UnregisterMessage as below? Previous code did remove message ID 0 (I should not code in OE 8-) corrected code: procedure TIcsWndHandler.UnregisterMessage(var Msg: UINT); var LMsg: TMsg; // == added begin if Msg = 0 then Exit; if FMsgLow WM_USER then raise EIcsException.Create('MsgLow not defined'); if Msg = (FMsgLow + WH_MAX_MSG) then raise EIcsException.Create('Msg value out of bound'); if not Assigned(FMsgMap[Msg - FMsgLow]) then raise EIcsException.Create('Msg not registered'); FMsgMap[Msg - FMsgLow] := nil; Dec(FMsgCnt); while PeekMessage(LMsg, FHandle, Msg, Msg, PM_REMOVE) do {loop}; // == added Msg := 0; if FMsgCnt = 0 then DeallocateHWnd; end; -- 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
[twsocket] ICS Wnd Control - Possible bug
Hello all While I was trying to use TICSWndControl as base class to share handles for message and consume less OS resources I ran into a very strange problem, that took me some nights of sleep, after a lot of researching I have found a problem in WndControl shared handles implementation, and I made an example program that shows the problem I will try to explain the situation The main problem is in the management of registered message queue, when you create a new object it will register its message to the message assignment queue by using AllocateMsgHandlers, so I create I component and it will assign the message 1025 to FMsgRelease, if I create another one, it will assign message 1026 to FMsgRelease of the other control If I Post message 1025 to the first component, just after posting I free it, it will release 1025 from the message queue, making it available for use, and then I create a new component (It will assign 1025 for the new control). When the message is received, it will be received by the third component, but I sent the message to the first one! In my demo program I simulate the following situation: I have two types of classes (TMyControl and TMyControl2) On TMyControl I register a test message TMyControl2 is simple descendent of TICSWndControl, the only thing is that it will call AllocateHWnd on constructor, so it will allocate the release message The path to error: - Create one instance of TMyControl (Messages 1025 and 1026 will be reserved for it (1025 = Release, 1026 = Test) - Create another instance of TMyControl (Messages 1027 and 1028 will be reserved for it) - Post message 1026 to first instance (1026 is a test message) - Free first instance of TMyControl (That was supposed to receive the message, but messages 1025 and 1026 will be released and free to be used for another control) - Create an instance of TMyControl2 (Message 1025 will be assigned to it as FMsgRelease) - Create an instance of TMyControl2 (Message 1026 will be assigned to it as FMsgRelease) Ok, when the handle received message 1026 (That was a message supposed to be received by an instance of TMyControl) it will be actually received by the second instance of TMyControl2, which will release the control since 1026 is now mapped to FMsgRelease message!! Do you have any suggestion of fix? I thought that when releasing a message handler we must in some way clean the message queue if there is any message in windows queue that was directed to that component, but how to do it? The link for test application is: www.intertruco.com.br/download/ICSWndError.rar Thank you very much Eric -- 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