Solved

Component1.method1 := Component2.Method1??

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

9 Experts available now in Live!

Get 1:1 Help Now