Solved

Component1.method1 := Component2.Method1??

Posted on 2000-03-02
5
129 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

762 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