?
Solved

Sending a self made message.

Posted on 1997-06-13
9
Medium Priority
?
159 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 150 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
Technology Partners: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 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