Solved

Sending a message to another component

Posted on 2000-02-27
9
191 Views
Last Modified: 2010-04-04
I am designing my own component, it is composed of a TPanel witch contains a TImage, now I
want to let the TPanel to know that an image has been loaded into the TImage. So I create
an message:

Const
     U_WM_LoadImage = WM_APP + 400;

Type
    TU_WM_LoadImage = Record
         Msg : Cardinal;
         Temp: Word;
         Image: TImageExt;
         Result : LongInt;
end;

and make a
      Dispatch(U_Message);
call in my LoadImage procedure. I then proceed to declare a message handler in my TPanel
component

procedure UWMLoadImage(var Message: TU_WM_LoadImage); message U_WM_LoadImage;

where I simply let it show a message.

This does not work, why and how can i make it work?

Need urgent ansewer! = High points

Thanks
0
Comment
Question by:MrBig
[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
  • 3
  • 3
  • 3
9 Comments
 
LVL 7

Expert Comment

by:ahalya
ID: 2562637
Don't know whether this helps, but just a few observations:

from the Help File:

The only assumption Dispatch makes about the data in Message is that the first two bytes contain a message ID, which is an integer-type number..


Isn't cardinal is 4 bytes ? (in 32 bit Delphi ?).  - why not Msg  :Word;
also i hope you are assigning U.Msg := U_WM_LoadImage ;
0
 

Author Comment

by:MrBig
ID: 2562721
ahalya:

The Msg should acturlly be of the type TMsgParam, but the compiler wont recognize that type, I read somewhere that TMsgParam actually is Cardinal so I tried it like that, but still now luck.
And yes I assign U.Msg := U_WM_LoadImage ;
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2562726
Your declaration has to be:
Type
    TU_WM_LoadImage = packed record
      Msg : Cardinal;
      Temp: LongInt;
      Image: TImageExt; // not very proper declaration but should work
      Result : LongInt;
    end;
ptm.
0
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!

 
LVL 7

Expert Comment

by:ahalya
ID: 2562737
You would have tried "packed" i suppose. (as in)

Type
 TU_WM_LoadImage =packed Record
       Msg : Cardinal;
       Temp: Word;
       Image: TImageExt;
       Result : LongInt;
       end;

just wondering; so don't bother responding if it doesn't work !
0
 
LVL 7

Expert Comment

by:ahalya
ID: 2562740
oops, i didn't see ptmcomp's message.
0
 

Author Comment

by:MrBig
ID: 2562789
I had missed the 'packed' bit but it still dosen't work, let me give you all the facts.

In a separate unit I declare:

unit TypeConstantLib;

interface
uses
  Windows, Messages,ImageExt;
Const
     U_WM_LoadImage = WM_APP + 400;

Type
    TU_WM_LoadImage = Packed Record
         Msg : Cardinal;
         Temp: Word;
         Image: TImageExt;
         Result : LongInt;
end;

In my component
ImageExt: (modified TImage)

Procedure TImageExt.LoadExtFromFile(const FileName: string);
Var U_Message :TU_WM_LoadImage;
Begin
     U_Message.Msg := U_WM_LoadImage;
     U_Message.Image := Self;
  try
    Self.Picture.LoadFromFile(Filename);
  except
    on EInvalidGraphic do
      Self.Picture.Graphic := nil;
  end;
      Dispatch(U_Message);    //Here I dispatch the                                              message
end;


In my component
ImageCont: (TPanel)

  private
      FImage : TImageExt;
  protected
      procedure UWMLoadImage(var Message:       TU_WM_LoadImage); message U_WM_LoadImage;

constructor TImageCont.Create(AOwner: TComponent);
Begin
  inherited;
  FImage:=TImageExt.Create(Self);
end;

procedure TImageCont.UWMLoadImage(var Message: TU_WM_LoadImage);
Begin
     Showmessage('asdfasd');
end;        //This should happen when an image is                  loaded
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 2562810
Look at my declaration: Temp: LongInt; instead of Temp: Word;
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 200 total points
ID: 2562823
Oh, I think you shoudn't dispatch the message to the default handler. Change this line to:
Onwer.BroadCast(U_Message);
If you know the instance of your panel, it was better to send the message directly:
Panel1.Perform(....)
ptm.
0
 

Author Comment

by:MrBig
ID: 2563138
I solved it my self, and I did as ptmcom now suggested, so I'm giving him the points...

Tanx all
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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