TLama

Untitled

May 11th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.90 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ExtCtrls, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Shape1: TShape;
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     procedure ShapeMouseDown(Sender: TObject; Button: TMouseButton;
  16.       Shift: TShiftState; X, Y: Integer);
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.dfm}
  27.  
  28. procedure TForm1.ShapeMouseDown(Sender: TObject; Button: TMouseButton;
  29.   Shift: TShiftState; X, Y: Integer);
  30. begin
  31.   TShape(Sender).Brush.Color := clRed;
  32. end;
  33.  
  34. procedure TForm1.Button1Click(Sender: TObject);
  35. var
  36.   Shape: TShape;
  37. begin
  38.   Shape := TShape.Create(Self);
  39.   Shape.Parent := Self;
  40.   Shape.OnMouseDown := ShapeMouseDown; // <- for each created object assign the private event handler method
  41. end;
  42.  
  43. end.
Advertisement
Add Comment
Please, Sign In to add comment