Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.453 Beiträge
Delphi 12 Athens
|
AW: PopupMenu dynamisch EventHandler zuweisen - Observer pattern?
2. Feb 2017, 16:59
Vielleicht so?
Delphi-Quellcode:
type
TMyComp = class(TControl)
private
function GetPopupMenu: TPopupMenu;
procedure myOnPopupMethod(Sender: TObject);
procedure SetPopupMenu(const Value: TPopupMenu);
protected
procedure Loaded; override;
published
property PopupMenu: TPopupMenu read GetPopupMenu write SetPopupMenu;
end;
procedure TMyComp.Loaded;
begin
inherited;
if PopupMenu <> nil then begin
PopupMenu.OnPopup := myOnPopupMethod;
end;
end;
procedure TMyComp.myOnPopupMethod(Sender: TObject);
begin
// ...
end;
function TMyComp.GetPopupMenu: TPopupMenu;
begin
Result := inherited PopupMenu;
end;
procedure TMyComp.SetPopupMenu(const Value: TPopupMenu);
begin
inherited PopupMenu := Value;
if PopupMenu <> nil then begin
PopupMenu.OnPopup := myOnPopupMethod;
end;
end;
|