MrBig
asked on
Component1.method1 := Component2.Method1??
Hi u all!
I have a problem (now doesn't everyone?) Well here it is:
Im building custom component, it's basically an Image container. It's a desendant from TPanel and in the create method i Create an TImage on it. Now that works fine. But when I put code in the OnClick event for example I need to click on the TPanel surface to execute the code if I click on the image nothing happens, this is not so strange. And I solved it by dispatching an WM_LMOUSEDOWN message to the owner. But this is a 'workaround' and it gets messy since I need to dispatch messages for all events (like OnMouseMove and so on). I have tried to assign the method of the owner to the corresponding method of the Image but i dosen't work.
Self.OnClick := (Owner as TImageCont).OnClick;
Why? Any other ideas? Maby I could override the WND procedure and dispatch all messages to the owner... if so how?
Tanx all
I have a problem (now doesn't everyone?) Well here it is:
Im building custom component, it's basically an Image container. It's a desendant from TPanel and in the create method i Create an TImage on it. Now that works fine. But when I put code in the OnClick event for example I need to click on the TPanel surface to execute the code if I click on the image nothing happens, this is not so strange. And I solved it by dispatching an WM_LMOUSEDOWN message to the owner. But this is a 'workaround' and it gets messy since I need to dispatch messages for all events (like OnMouseMove and so on). I have tried to assign the method of the owner to the corresponding method of the Image but i dosen't work.
Self.OnClick := (Owner as TImageCont).OnClick;
Why? Any other ideas? Maby I could override the WND procedure and dispatch all messages to the owner... if so how?
Tanx all
Okay....
First, make a TnotifyEvent of your own:
FOnCLick:TnotifyEvent;
next, in the constructor of the Image component, assign it's OnClick to a routine your have written.
Procedure DoMouseClick(Sender:Tobjec t);
begin
If Assigned(FOnClick) then OnClick(Self);
end;
{Image constructor}
image:=Timage.create;
image.align:=alclient;
image.onclick:=DoMouseClic k;
Last, Publish the OnClick Property:
Published
Property OnCLick:TNotifyEvent read FOnclick Write FOnClick;
This is off the top of my head, so the syntax might be a little off, but the basics are there. I have done this in the past and can give you some sample code if you get stuck. Good luck!!
First, make a TnotifyEvent of your own:
FOnCLick:TnotifyEvent;
next, in the constructor of the Image component, assign it's OnClick to a routine your have written.
Procedure DoMouseClick(Sender:Tobjec
begin
If Assigned(FOnClick) then OnClick(Self);
end;
{Image constructor}
image:=Timage.create;
image.align:=alclient;
image.onclick:=DoMouseClic
Last, Publish the OnClick Property:
Published
Property OnCLick:TNotifyEvent read FOnclick Write FOnClick;
This is off the top of my head, so the syntax might be a little off, but the basics are there. I have done this in the past and can give you some sample code if you get stuck. Good luck!!
hi mrbig,
try it in the other way like
if assigned(self.Onclick) then
if assigned(FImage) then
FImage.OnClick := self.OnClick;
meikl
try it in the other way like
if assigned(self.Onclick) then
if assigned(FImage) then
FImage.OnClick := self.OnClick;
meikl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
edey:
Thanx for the tip, but the thing is that I need TImage propertys and procedures since it is a modifyed version of TImage I am using (one that can handle all formats).
DrDelphi:
I'll try yours...
Thanx for the tip, but the thing is that I need TImage propertys and procedures since it is a modifyed version of TImage I am using (one that can handle all formats).
DrDelphi:
I'll try yours...
Gl
Mike