The event OnClick on the shape works great.
Is there any way to assign a new event "OnDblClick" to the shape at runtime?
Both OnClick and OnDblClick are not published by TShape, but OnClick is public by default, but OnDblClick is protected.
Use class helpers to get protected properties:
type
TSetOnDbkClickHelper = class helper for TControl
procedure SetDblClick(DblClickEvent: TNotifyEvent); inline;
end;
procedure TSetOnDbkClickHelper.SetDblClick(DblClickEvent: TNotifyEvent);
begin
OnDblClick := DblClickEvent;
end;
Test with TShape on Form OK:
type
TForm1 = class(TForm)
Shape1: TShape;
procedure FormCreate(Sender: TObject);
private
procedure ShapeDblClick(Sender: TObject);
end;
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
// Shape1.OnDblClick := nil;
Shape1.SetDblClick(@ShapeDblClick);
end;
procedure TForm1.ShapeDblClick(Sender: TObject);
begin
Caption := 'Double click time ' + TimeToStr(Time);
end;