home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / polybtn / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  1.3 KB  |  65 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: POLYBTN }
  5.  
  6. { An example showing how you can dynamically switch which OnClick
  7.   methods are associated with a button. The programs starts out
  8.   with the FoodClick method being associated with the Food
  9.   button. At run time, you can switch the delegation model
  10.   so that the WorkClick method is associated with the Food
  11.   button. }
  12.  
  13. interface
  14.  
  15. uses
  16.   WinTypes, WinProcs, Classes,
  17.   Graphics, Forms, Controls,
  18.   StdCtrls;
  19.  
  20. type
  21.   TForm1 = class(TForm)
  22.     Food: TButton;
  23.     SetWork: TButton;
  24.     SetFood: TButton;
  25.     ListBox1: TListBox;
  26.     procedure FoodClick(Sender: TObject);
  27.     procedure WorkClick(Sender: TObject);
  28.     procedure SetWorkClick(Sender: TObject);
  29.     procedure SetFoodClick(Sender: TObject);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TForm1.WorkClick(Sender: TObject);
  44. begin
  45.   ListBox1.Items.Add('This is a work click');
  46. end;
  47.  
  48. procedure TForm1.FoodClick(Sender: TObject);
  49. begin
  50.   ListBox1.Items.Add('This is a food click');
  51. end;
  52.  
  53. procedure TForm1.SetWorkClick(Sender: TObject);
  54. begin
  55.   Food.OnClick := WorkClick;
  56. end;
  57.  
  58. procedure TForm1.SetFoodClick(Sender: TObject);
  59. begin
  60.   Food.OnClick := FoodClick;
  61. end;
  62.  
  63. end.
  64.  
  65.