Solved

Component1.method1 := Component2.Method1??

Posted on 2000-03-02
5
131 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

726 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