Solved

Component1.method1 := Component2.Method1??

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 79
Create a path if not exists 7 69
Find and Replace Stream with 0s 8 57
Base1 Encode/Decode 3 68
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now