0

我正在开发以下带有 TPopupMenu 的组件。注册组件后,我可以在设计时在 PopupMenu2.Items 中添加菜单声音,但它们不会在运行时显示。

你知道为什么会发生这种情况以及我该如何解决这个问题吗?

type
  TREditWithTags = class(TFrame)
    PopupMenu2: TPopupMenu;
    procedure Popup
    Menu2Change(Sender: TObject; Source: TMenuItem; Rebuild: Boolean);
  private
     { Private declarations }
      RVeditor:TrichEdit;
      FPopUpEnabled:Boolean;
      procedure GetPopUp(Sender: TRichEdit; Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
  public
     { Public declarations }
      procedure Loaded;override;
  protected
      procedure OnMenuItemClicked(Sender: TObject);override;
  published

  end;


implementation

{$R *.dfm}

procedure TREditWithTags.OnMenuItemClicked(Sender: TObject);
begin
  inherited;
 (RVEditor as TrichEdit).Lines.Add((Sender as TMenuItem).Caption);
end;


procedure TREditWithTags.PopupMenu2Change(Sender: TObject; Source: TMenuItem;  Rebuild: Boolean);
var
  i:TMenuItem;
begin
  for i in PopupMenu2.Items do
    i.OnClick:=OnMenuItemClicked;
end;

procedure TREditWithTags.SetRVEditor(Editor: TRichEdit);
begin
  inherited;
  if PopUpEnabled then
    RVEditor.OnRVMouseDown:=GetPopUp;
end;

procedure TREditWithTags.Loaded;
var
  i:TMenuItem;
begin
  inherited Loaded;
  if RVEditor is TRichEdit then
  begin
    for i in PopupMenu2.Items do
      i.OnClick:=OnMenuItemClicked;
    FRVEditor.OnRVMouseDown:=GetPopUp;
  end;
end;

procedure TREditWithTags.GetPopUp(Sender: TrichEdit; Button: TMouseButton; Shift:TShiftState; ItemNo, X, Y: Integer);
begin
  if Button=mbRight then
    PopupMenu2.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y+10);
end;

end.
4

0 回答 0