home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: POLYBTN }
-
- { An example showing how you can dynamically switch which OnClick
- methods are associated with a button. The programs starts out
- with the FoodClick method being associated with the Food
- button. At run time, you can switch the delegation model
- so that the WorkClick method is associated with the Food
- button. }
-
- interface
-
- uses
- WinTypes, WinProcs, Classes,
- Graphics, Forms, Controls,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Food: TButton;
- SetWork: TButton;
- SetFood: TButton;
- ListBox1: TListBox;
- procedure FoodClick(Sender: TObject);
- procedure WorkClick(Sender: TObject);
- procedure SetWorkClick(Sender: TObject);
- procedure SetFoodClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.WorkClick(Sender: TObject);
- begin
- ListBox1.Items.Add('This is a work click');
- end;
-
- procedure TForm1.FoodClick(Sender: TObject);
- begin
- ListBox1.Items.Add('This is a food click');
- end;
-
- procedure TForm1.SetWorkClick(Sender: TObject);
- begin
- Food.OnClick := WorkClick;
- end;
-
- procedure TForm1.SetFoodClick(Sender: TObject);
- begin
- Food.OnClick := FoodClick;
- end;
-
- end.
-
-