Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending a message to another component

Posted on 2000-02-27
9
Medium Priority
?
194 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
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

927 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