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
Solved

Sending a self made message.

Posted on 1997-06-13
9
151 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 121
Reconfigure Delphi Install? 2 61
Create a path if not exists 7 89
how to resize animated Gif image in delphi ? 1 35
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

829 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