Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls;
- type
- TForm1 = class(TForm)
- Shape1: TShape;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- procedure ShapeMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.ShapeMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- TShape(Sender).Brush.Color := clRed;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- Shape: TShape;
- begin
- Shape := TShape.Create(Self);
- Shape.Parent := Self;
- Shape.OnMouseDown := ShapeMouseDown; // <- for each created object assign the private event handler method
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment