Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

service postmessage problem

Posted on 2006-10-29
4
Medium Priority
?
324 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 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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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