Solved

Sending a message to another component

Posted on 2000-02-27
9
186 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
  • 3
  • 3
  • 3
9 Comments
 
LVL 7

Expert Comment

by:ahalya
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Expert Comment

by:ahalya
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:ahalya
Comment Utility
oops, i didn't see ptmcomp's message.
0
 

Author Comment

by:MrBig
Comment Utility
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
Comment Utility
Look at my declaration: Temp: LongInt; instead of Temp: Word;
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 200 total points
Comment Utility
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
Comment Utility
I solved it my self, and I did as ptmcom now suggested, so I'm giving him the points...

Tanx all
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now