Solved

Sending a self made message.

Posted on 1997-06-13
9
150 Views
Last Modified: 2010-04-06
How do I make, send and receive a message in Delphi pascal 2.0 (and Win95) from an application to a thread?
0
Comment
Question by:Lillan061397
  • 5
  • 4
9 Comments
 

Author Comment

by:Lillan061397
ID: 1337010
Edited text of question
0
 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1337011
There are two categories of your own messages.  Those that start at WM_User.  ie.   CONST MyMsg = WM_USER + 101.  and system unique messages you get from  MyMsg := RegisterWindowMessage('Some unique string' );

You can SendMessage( Handle, MyMsg, hparm, lparm ), Or PostMessage which places the message in the queue and returns immediately, or perform to send it your own window.

The techniques for receiving are various.  You can declare a local window message like PROCEDURE WMMyMessage( VAR MSG: TMEssage);  Message MyMsg;  and then implement it in the form object.
You can out a handler in the application.onmessage event, and several other more sophisticated techniques.  

These are all described in the Delphi Documentation rather well.  Take a look, if you still need help, let me know.

Cheers,
Ian C.

0
 

Author Comment

by:Lillan061397
ID: 1337012
I use the procedure WMMyMessage( VAR MSG: TMEssage); Message MyMsg;, but that doesn't work!!! It's location is in the thread, but nothing happens.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 2

Expert Comment

by:icampbe1
ID: 1337013
Hi again,

Once you have implemented the MyMessage handler in the form (ie made it a message handling method and implemented it), you can then invoke it by sending a message if that type (number) to the window which contains the definition.  You specify the handle of the window that has the declaration and that expects to receive the message.

It you want to test the facility, simply 'perform' from the same form object and specity your Message ID then work from there.  If this doesn't work, you will have to show me some code and I'll try and determine what you missed.

Cheers,
Ian C.

0
 

Author Comment

by:Lillan061397
ID: 1337014
Here is the code that I'm using.

    const
      WM_TESTMESS = 10000 + WM_USER;  //Declarated in Constants.pas

     type
      TWMTestMess = record
        Msg: Cardinal;
      end;  // Declarated in Types.pas

     procedure TTestThread.WMTestMess(var Message: TWMTestMess);
     begin
        Form1.Caption:='Okej';
     end;   //Declarated in TestThread.pas

     PostThreadMessage(FTestT.ThreadID, WM_TESTMESS,0,0); //This is done in Main.pas, which is the mainprojekt. It uses Constants, Types and TestThread. FTestT is Created with TTestThread.Create(Form1); The reason I'm using Form1 is that I want to write in the mainform. The procedure behind Create is inherited Create(False);.
What am I doing wrong????  
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337015
You must declare the procedure as a message procedure:
 
TYPE xxx= CLASS( yyy)
PRIVATE
  PROCEDURE WMTestMsg( VAR Msg:TMEssage); Message; WM_TestMess;

Then, You must implement it.
Procedure xxx.WMTestMSg( VAR Msg.TMessage);
BEGIN
 ....
END;

DO NOT create a mesage type... Use TMessage as the type.  VAR Msg: TMessage.

Declare the procedure using the keyword 'Message' as show above.

I look later on for more comments.  I hope this helps.

Ian C.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337016
Also, it isn't necessary to use such a large message number.  Use WM_TestMsg = WM_User + 500.  This will make it unique.
There are some controls that use WM_User +... but only for the first 50 or 60 as I recall.  WM_User +500 is very safe.

0
 

Author Comment

by:Lillan061397
ID: 1337017
I've changed the messagetype and the message number. Thanks! The class yyy is TThread. Now I think that I'm doing everything right, but it still doesn't work. I've tried with
var Koll : Boll;
    Mess : TMsg;
Koll:= GetMessage(Mess,Null,WM_TESTMESS,WM_TESTMESS);
When I'm using this I get an EVariantError whith the code:
'Invalid variant type conversion'. I think that it is the TMsg type, but that is just my guess. Do I have to use GetMessage? Sorry for bothering you!

Thanks Lillan.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337018
No, you do not use GetMessage.  Look at my previous example.
 The procedure  Procedure xxx.WMTestMSg( VAR Msg: TMessage)  wiill be called when you send the message.  It must be declared in the object as a message procedure (
PROCEDURE WMTestMsg( VAR Msg:TMEssage); Message; WM_TestMess; )  Also, the type  is 'TMessage' not 'TMsg'.

I have to leave right now,  send me a piece of your code to E-Mail:  iancamp@interlog.com  and I'll look at it this evening (I'm in Toronto).  It will be easier if I can see more specifically what you have.

Also, there is no need to appologize for asking questions.  That is what helping others is all about.  Sometime, I may be asking you for help.

Ian Campbell

0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 395
Virtuailstring tree compare node issue 14 116
Using idhttp to login to instagram 2 89
control image tags in a string ? 12 129
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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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