掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
PopupMenu の処理を共通にするには? (ID:18742)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> ListBoxCompo := TListBox(TPopupMenu(Sender).PopupComponent); ここが間違っています。 Sender は TPopupMenu ではなく、TMenuItem です。 下記のコードで動作します。 procedure TForm1.componentClick(Sender: TObject); var APopupMenu: TPopupMenu; AListBox : TListBox; begin if (Sender is TListBox) then begin TListBox(Sender).PopupMenu.PopupComponent:= TListBox(Sender); TListBox(Sender).PopupMenu.Popup(Mouse.CursorPos.x, Mouse.CursorPos.y); end else if (Sender is TMenuItem) then begin APopupMenu:= TPopupMenu(TMenuItem(Sender).GetParentMenu); if Assigned(APopupMenu) then begin AListBox:= TListBox(APopupMenu.PopupComponent); if Assigned(AListBox) and (AListBox.ItemIndex >= 0) then ShowMessage(AListBox.Items[AListBox.ItemIndex]); end; end; end;
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.