Solved

Sending a message to another component

Posted on 2000-02-27
9
188 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 214
Create Database on Android via Delphi dbExpress 3 90
Delphi selector screen 2 78
Reconfigure Delphi Install? 2 51
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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