type
TMyMouseEvent = procedure(Sender:TObject; Realte:TControl; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer; Var DoIt: Boolean);
TMycomponent = class(TCustomControl)
private
...
fRelateComponent: TControl;
fOldOnMouseDown: TMouseEvent;
fRelateComponentMouseDown: TMyMouseEvent;
procedure NewOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SetRelateComponent(Value: TControl);
public
...
published
...
property RelateComponent: TControl read fRelateComponent write SetRelateComponent;
property OnRelateComponentMouseDown: TMyMouseEvent read fRelateComponentMouseDown write fRelateComponentMouseDown;
end;
procedure TMycomponent.SetRelateComponent(Value: TControl);
begin
if Assigned(fRelateComponent) then
fRelateComponent.OnMouseDown := fOldOnMouseDown;
fRelateComponent := Value;
if Assigned(fRelateComponent) then
begin
fOldOnMouseDown := fRelateComponent.OnMouseDown;
fRelateComponent.OnMouseDown := NewOnMouseDown;
end
else
fOldOnMouseDown := nil;
end;
procedure TMycomponent.NewOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
DoIt: Boolean;
begin
if assigned(fRelateComponentMouseDown) then
fRelateComponentMouseDown(Sender, fRelateComponent, Button, Shift, X, Y, DoIt);
if Doit then
fOldOnMouseDown(Sender, Button, Shift, X, Y);
end;
大致如此,没有经过测试。