D

You can you it with RTTI, Hope this helps

    FControlEvent: TMethod;
    FNewOnControlEvent: TMethod;


procedure TControlLink.SetOnControlEvent;
begin
  if not (csDesigning in ComponentState) and
         (FControl <> nil) and
         (FEventName <> '') then
  if IsPublishedProp(FControl,FEventName) then
  begin
    FControlEvent := GetMethodProp(FControl,FEventName);
    with FNewOnControlEvent do
    begin
      Code := @TControlLink.OnControlEvent;
      Data := Self;
    end;
    SetMethodProp(FControl,FEventName,FNewOnControlEvent);
  end;
end;

procedure TControlLink.ResetOnControlEvent;
begin
  if not (csDesigning in ComponentState) and (FControl <> nil) then
  begin
    FNewOnControlEvent := GetMethodProp(FControl,'OnControlEvent');
    if FNewOnControlEvent.Data = Self then {still pointing at us}
      SetMethodProp(FControl,'OnControlEvent',FControlEvent);
   end;
end;

procedure TControlLink.OnControlEvent;
begin
  if not FActive then Exit;
  if FControl <> nil then
  begin
     // do our stuff
  end;
  if Assigned(FControlEvent.Code) then // call the original
    TNotifyEvent(FControlEvent)(TObject(FControl));
end;


----- Original Message -----
From: "Donovan J. Edye" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Thursday, November 21, 2002 11:42 AM
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.
> ----------------------------------------------------------------------
>

---------------------------------------------------------------------------
    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