Solved

Sending a self made message.

Posted on 1997-06-13
9
153 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
[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
  • 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
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!

 
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

Independent Software Vendors: 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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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