Die musst SetMethoden für deine MenuItems erstellen:
Delphi-Quellcode:
interface
{...}
type
TMyTreeView = class(TTreeView)
private
FCopyMenuItem: TMenuItem;
FOldCopyOnClick: TNotifyEvent;
procedure SetCopyMenuItem(const Value: TMenuItem);
procedure MyMenuItemOnClick(Sender: TObject);
published
property CopyMenuItem: TMenuItem read FCopyMenuItem write SetCopyMenuItem;
end;
implementation
procedure TMyTreeView.MyMenuItemOnClick(Sender: TObject);
begin
{...}
end;
procedure TMyTreeView.SetCopyMenuItem(const Value: TMenuItem);
begin
if FCopyMenuItem <> Value then
begin
if Assigned(FCopyMenuItem) then
// alten Eventhandler wieder zuweisen
FCopyMenuItem.OnClick := FOldCopyOnClick;
// MenuItem zuweisen
FCopyMenuItem := Value;
if Assigned(FCopyMenuItem) then
begin
// alten Eventhandler "retten"
FOldCopyOnClick := FCopyMenuItem.OnClick;
// eigenen Eventhandler zuweisen
FCopyMenuItem.OnClick := MyMenuItemOnClick;
end;
if Value <> nil then
Value.FreeNotification(Self);
end;
end;
{...}