Solved

Sending a message to another component

Posted on 2000-02-27
9
187 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

912 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

18 Experts available now in Live!

Get 1:1 Help Now