Solved

service postmessage problem

Posted on 2006-10-29
4
313 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
Comment Utility
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
Comment Utility
or try PostThreadMessage
ziolko.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

11 Experts available now in Live!

Get 1:1 Help Now