I have created a new compound component based on a TCustomPanel
.
On it I have two labels and one image, covering all the surface, see this layout (the lower part is less important):
My question is how to export the double click functionality of any of these controls? Is it a possibility to use the double click (event) of the new control to manage those of the child controls on it?
I think you should do it by using the following approach:
OnDblClick
event to the compound component.FOnInternalDblClick
(The name is not important), compatible with TNotifyEvent
to your compound component.FOnInternalDblClick
, execute the compound component's OnDblClick
.FOnInternalDblClick
to the OnDblClick
event of every component for which you want to manage the event.Example code:
TMyCompoundComponent = class(TCustomPanel)
protected
FOnDblClick : TNotifyEvent;
procedure FOnInternalDblClick(ASender : TObject);
public
constructor Create(AOwner : TComponent); override;
published
property OnDblClick : TNotifyEvent read FOnDblClick write FOnDblClick;
end;
constructor TMyCompoundComponent.Create(AOwner : TComponent);
begin
inherited;
//Lab1.OnDblClick := FOnInternalDblClick;
//Lab2.OnDblClick := FOnInternalDblClick;
//...
end;
procedure TMyCompoundComponent.FOnInternalDblClick(ASender : TObject);
begin
if(Assigned(FOnDblClick))
then FOnDblClick(ASender);
end;
Note:
In the compound component's OnDblClick
event handler, the ASender
parameter will be the internal component (Lab1
, Lab2
, Lab3
...). If you prefer to receive the compound component itself as ASender
parameter, you could change the FOnInternalDblClick
method by passing Self
instead of ASender
:
procedure TMyCompoundComponent.FOnInternalDblClick(ASender : TObject);
begin
if(Assigned(FOnDblClick))
then FOnDblClick(Self);
end;