All you need to do is use that external condition to
decide in the TNotify event whether to execute the
code or not in a decision branch (a lot of programmers
use the Tag property for this):

For example: (some external event sets the tag
property of the speedbutton)

procedure TForm.SpeedbuttonClick(Sender: TObject);
begin
If Speedbutton.tag = 0 Then Exit
else If Speedbutton.tag = 1 Then
 begin
  //code that is in the first TNotify event
 end
else If Speedbutton.tag = 2 Then
  begin
    //code that is in 2nd TNotifyEvent
  end;
end;

  from what you've explained, I see no reason to be
swapping TNotify events in and out (although it's
certainly doable).

Dave

--- "Jamie L. Mitchell" <[EMAIL PROTECTED]>
wrote:

> Hello all:
> 
> I am making something that should be really easy
> into something really
> difficult; 
> 
> I have created a composite control, containing an
> edit box and several
> speed buttons.  One of the speed buttons, on the
> click event, I would
> like to substitute a new event for the TNotifyEvent
> that normally occurs. 
> 
> The original code using the default handler looks
> like this:
> ------------------
> Function GetBtn1Click: TNotifyEvent;
> Procedure SetBtn1Click(const E: TNotifyEvent);
> 
> property OnBtn1Click: TNotifyEvent read GetBtn1Click
> write SetBtn1Click;
> 
> Function TjmEdit.GetBtn1Click: TNotifyEvent;
> Begin
>    Result := FBtn1.OnClick;
> End;
> Function TjmEdit.SetBtn1Click(const E: TNotifyEvent)
> Begin
>    FBtn1.OnClick := E;
> End;
> -------------------
> This works - when I create a handler to deal with
> the click it works fine.
> 
> Here is what I want, however.  I would like to
> create this component
> such that it will allow me to attach a different
> event handler
> signature.  For example, I want to define my new
> event as follows:
> 
> TjmFileRefBtnPressedEvent = procedure(Sender:
> TObject; var FileRec:
>                            Integer; var FileName:
> String) of object;
> 
> I would like to assign this to the button click
> instead of the
> TNotifyEvent (the compiler absolutely hates this,
> since the procedure
> signature is different.)  
> 
> What kind of magic do I need to do to get this to
> work?  Ideally,
> inside my component, some kind of code will act as a
> moderator
> between the original TSpeedButton.OnClick event and
> the new
> TjmFileRefBtnPressedEvent.  If no event handler is
> assigned, pressing
> the button would do nothing.  If I assign a handler,
> such as 
> 
> Procedure WorkWithFileRepository(Sender: TObject;
> Var Key: Integer; 
>                                  Var Fil: String);
> 
> then pressing the button would execute this method.
> 
> Thank
> jamie
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 



 
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

Reply via email to