Einzelnen Beitrag anzeigen

Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.453 Beiträge
 
Delphi 12 Athens
 
#5

AW: PopupMenu dynamisch EventHandler zuweisen - Observer pattern?

  Alt 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;
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat