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