Solved

service postmessage problem

Posted on 2006-10-29
4
315 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
4 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 25 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 25 total points
ID: 17832377
or try PostThreadMessage
ziolko.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now