Solved

Component1.method1 := Component2.Method1??

Posted on 2000-03-02
5
130 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:MrBig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2577467
Might be easier to keep a private TBitmap & draw it to the panel yourself, this way you have no confusion as to who gets what msg.

Gl
Mike
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2577473
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:Tobject);
begin
  If Assigned(FOnClick) then OnClick(Self);
end;


{Image constructor}
image:=Timage.create;
image.align:=alclient;
image.onclick:=DoMouseClick;


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





0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2577474
hi mrbig,

try it in the other way like

if assigned(self.Onclick) then
  if assigned(FImage) then
   FImage.OnClick := self.OnClick;

meikl
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 200 total points
ID: 2577530
Stripped down (but functional) example:

========================================

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TNothing = class(TCustomPanel)
  private
    Image:Timage;
    FONClick:Tnotifyevent;
    Procedure DoMouseClick(sender:Tobject);
    { Private declarations }
  protected
    { Protected declarations }
  public
    Constructor create(Aowner:TComponent);override;
    { Public declarations }
  published
    { Published declarations }
    Property OnCLick:TnotifyEvent read FonCLick write Fonclick;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('DrDelphi', [TNothing]);
end;


Constructor TNothing.create(Aowner:TComponent);
begin
  Inherited create(Aowner);
  image:=Timage.create(self);
  With image do
  begin
   Align:=AlClient;
   Parent:=(Owner as TWinControl);
   onclick:=DoMouseClick;
 end;  
end;
Procedure TNothing.DoMouseClick(sender:Tobject);
begin
   if assigned(FonClick) then OnClick(self);
end;
end.
0
 

Author Comment

by:MrBig
ID: 2577632
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...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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