Don't publish the actual embedded TButton's OnClick event.  Publish your
own (EmbeddedBtnClick) and then in the setter of the property tie the event
to the embedded comoponent.

something like this (extremely rough example)...

TMyPanel = class(TPanel)
private
  FEmbeddedBtnClick: TNotifyEvent;
  FButton: TButton;
  procedure EmbeddedClick(Sender: TObject);

public
  constructor Create(aOwner: TComponent); override;
published
  property OnEmbeddedBtnClick read FEmbeddedBtnClick write
SetEmbeddedBtnClick;
end;


constructor TMyPanel.Create(aOwner: TComponent);
begin
  FButton := TButton.Create(Self);
  FButton.Parent := Self;
  FButton.SetBounds(10, 10, 75, 25);
  FButton.OnClick := EmbeddedClick;
end;

procedure TMyPanel.EmbeddedClick(Sender: TObject);
begin
  // do my stuff before calling the event
  if Assigned(FEmbeddedBtnClick) then
      FEmbeddedBtnClick(FButton);
  // do my stuff after the event
end;

procedure TMyPanel.SetEmbeddedBtnClick(Value: TNotfiyEvent);
begin
  FEmbeddedBtnClick := Value;
end;

Something like this...........  (I said it was rough!)


JED




|---------+---------------------------->
|         |           "Donovan J. Edye"|
|         |           <[EMAIL PROTECTED]|
|         |           om.au>           |
|         |           Sent by:         |
|         |           owner-delphi@delp|
|         |           hi.org.nz        |
|         |                            |
|         |                            |
|         |           21/11/2002 09:42 |
|         |           AM               |
|         |           Please respond to|
|         |           delphi           |
|---------+---------------------------->
  
>--------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                |
  |       To:       Multiple recipients of list delphi <[EMAIL PROTECTED]>          
                                |
  |       cc:                                                                          
                                |
  |       Subject:  [DUG]:  [Q] Event Hooking.....                                     
                                |
  
>--------------------------------------------------------------------------------------------------------------------|




G'Day,

I was just curious about some approaches to achieve responding to the event
of an embedded component in my component. Clear as mud? An example:

Lets say I have a component MyComponent that has a published property
MyButton : TButton. Now I want to take some action when the user clicks the
button assigned to MyButton. However any code that they have assigned to
the click event for the button must also be fired.

So basically I want to transparently hook the OnClick event. The only way I
can think of doing this is by responding to the apropriate CN_*, CM_*
message. Is there another way to do this? If not what messages should I be
looking at responding to?




-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------





This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the [EMAIL PROTECTED]

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to