Here is the original version.
On 10/23/06, Mikael Ostensson <
[EMAIL PROTECTED]> wrote:
As several people have asked for this, I'll post it here.
The sample code in the previous example is based on windows API and is thus not cross plattform. I needed a similar messageing system that would compile in both linux(kylix) and windows(delphi).
Chages would most likely need to be performed to get it to compile under Freepascal.
It allows for queues shared by multiple threads and can be use to create thread pools.
You can pass messages as strings and/or object. All method access is thread safe.
Your main methods will be:
Post a message on the queue:
PostMessage(StringMessage : String; ObjectMessage : Tobject);
Blocking read, that will wait for posted message(usefull for creating thread pools):
Make sure to check the result that will indicate weather a message was retrieved.
If the message result is wrSignaled a object was released, if it is wrTimeout you, another tread retrieved the message and you need to re-call the method. if its wrAbandoned the queue object have been released and you are most likely shutting down
WaitForMessage(Var StringMessage:string;var ObjectMessage : Tobject): TWaitResult ;
non blocking call returns true if an object was retrieved
PeekForMessage(Var StringMessage:string;var ObjectMessage : Tobject): Boolean;
This is provided AS IS.
MikaelOn 10/23/06, Lloyd Thomas < [EMAIL PROTECTED]> wrote:Mikael, I would be very interested in your TMessageQueue. please can you send me a copy.thanksLloyd----- Original Message -----From: Mikael OstenssonTo: Ararat SynapseSent: Monday, October 23, 2006 4:35 PMSubject: Re: [Synalist] More 'echo' demo questionsYou need to creat your own message queue:
in the execute loop of the tread do something like:
if PeekMessage(msg,0,WM_USER,cMaxMsg,PM_REMOVE ) then
begin
case msg.message of
WM_YOUR_MESSAGE_TYPE:
begin
Proccess you message here
end;
WM_ANOTER_MESSAGE_TYPE:
begin
ProcessMessage here
end;
........
end;
end;
and use PostThreadMessage to send the message to the tread.
Look up the exact usage pf the APIs in the help.
Alternativly I have created a TMessageQueue that is Delphi/Kylix cross compatible.
If you are interest I can send it to you.
Mikael
On 10/23/06, Lloyd Thomas <[EMAIL PROTECTED]> wrote:I have based my app on the echo example, but I have another question. I can send the received starings to the main thread using 'postmessage' using the following, but I have no idea how I would send data back to the client from the main thread. Any Ideas?========================================procedure TTCPRecvThrd4.Execute;
var
// s: string;
LCmd: string;
MyDataParse4 : pMyDataParse4;
begin
sock:=TTCPBlockSocket.create;
try
Sock.socket:=CSock;
sock.GetSins;
with sock do
begin
repeat
if terminated then break;
LCMD := RecvString(500);
if lastError<>0 then break;
SendString(LCmd+#13#10);
New(MyDataParse4);
MyDataParse4.IPDataString := LCmd;
PostMessage(Application.MainForm.Handle, WM_MyDataParse4, 0, integer(MyDataParse4));
if lastError<>0 then break;
until false;
end;
finally
Sock.Free;
end;
end;==========================================
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public
uMessageQueue.pas
Description: Binary data
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ synalist-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/synalist-public
