Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

service postmessage problem

Posted on 2006-10-29
4
Medium Priority
?
325 Views
Last Modified: 2010-04-04
I have an app which I am converting to a service. The service consist of the service, a datamodule and a unit for various threads.
In the original app I was using post message to send strings to the mainform, but as the datamodule does not have a window handle this is a problem. I was only using postmessage as the old app would update a 'richedit' box on a window form. As there is now no  window forms what is the best way to get round my problem? Should I now just call the datamodule method directly?

DATAMODULE
====================================

{*****************************************************
Receive Data from Thread 4
******************************************************}
procedure TDataModule2.WMMyDataParse4(var Message: TMessage);
var
    CallString,p: String;
    EndStr,StrCheck: integer;
begin
   p := pMyDataParse4(Message.LParam).IPDataString;
   Dispose(pMyDataParse4(Message.LParam));
            Regex4 := TPerlRegEx.Create(nil);
            Regex4.RegEx := RegExpStr4;
            Regex4.Subject := p;
              if Regex4.Match then begin
              StrCheck := 1;
                  if RegExpEnd4 = '1' then begin
                  EndStr := 1;
                  StrCheck := 0;
                  end
                  else
                  Endstr := 0;
                  StrCheck :=1;
              end;
               if RegExpEnd4 <> '1' then begin
                Regex4.RegEx := RegExpEnd4;
                Regex4.Subject := p;
                if Regex4.Match then begin
                EndStr := 1;
                StrCheck := 0;
                end
                else begin
                EndStr := 0;
                StrCheck := 1;
                end;
               end;

                if EndStr = 1 then begin
                sysStr4 := sysStr4+p;
                CallString := CallConv(sysStr4,PhonesysID4);
                CallString := CallString+',4,4';
                ProcessSearch2(CallString);
                EndStr := 0;
                SysStr4 := '';
                end
                else begin
                if StrCheck = 1 then
                SysStr4 := SysStr4+p+#13#10;
                end;
end;
===========================================


UNIT2
==========================================

{***********************************************
Process calls for port4
***********************************************}
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(60000);
          if lastError<>0 then break;
          SendString(LCmd+#13#10);
          New(MyDataParse4);
          MyDataParse4.IPDataString := LCmd;
          PostMessage(collexServiceUnit2, WM_MyDataParse4, 0, integer(MyDataParse4));
          if lastError<>0 then break;
        until false;
      end;
  finally
    Sock.Free;
  end;
end;
===========================================
0
Comment
Question by:lloydie-t
2 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 100 total points
ID: 17832250
calling the datamodule method directly could be a good solution.
If you want to keep using messages you should take a look at AllocateHwnd();
This functions allows you to create a 'fake' window to be able to receive messages if you have no normal window.
You will probably also have to make your own message loop if you want this, so calling directly is a simpler option (maybe through an event?)
0
 
LVL 21

Assisted Solution

by:ziolko
ziolko earned 100 total points
ID: 17832377
or try PostThreadMessage
ziolko.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question