Solved

service postmessage problem

Posted on 2006-10-29
4
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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