Главная страница | назад





Article #16575: Reassigning events at runtime

 Question and Answer Database

FAQ1575D.txt   Reassigning events at runtime
Category   :Object Pascal
Platform    :All
Product    :All 32 bit  

Question:
How can I reassign an event at runtime?

Answer:
The following example demonstrates reassigning an event.

procedure TForm1.Button1Click(Sender: TObject);
var
  Button2SavedEvent : TNotifyEvent;
  Button3SavedEvent : TNotifyEvent;
begin
 {Save the events}
  Button2SavedEvent := Button2.OnClick;
  Button3SavedEvent := Button3.OnClick;

 {Clear button 2's OnClick event}
  Button2.OnClick := nil;

 {Set button 3's OnClick to Button2's old OnClick Event}
  Button3.OnClick := Button2SavedEvent;

  { Do something here }

 {Take us back to the original events}
  Button2.OnClick := Button2SavedEvent;
  Button3.OnClick := Button3SavedEvent;
end;

7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99