Recent

Author Topic: Popup Menu already exists?  (Read 734 times)

indydev

  • Full Member
  • ***
  • Posts: 118
Popup Menu already exists?
« on: September 15, 2023, 02:26:38 am »
I noticed that in my Memo control, a right click popup menu already exists allowing me to cut, paste, and copy. I didn't know that this was the case, however, I still see lots of references to making popup menus and assigning them to controls.

I have a couple of questions regarding this "automatic" popup menu:

1) Does this phenomenon occur across the big three OS's: Linux, Windows and MacOS?  I am on Linux Mint 21 and it's working for me.

2) Am I able to use OnContextPopup to execute some code if a "paste" has taken place?  I assume I need to get this menu assigned first, but a) maybe it already is? b) if it isn't assigned how I do that?  ...and if it is, is it just
Code: Pascal  [Select][+][-]
  1. Memo1.PopupMenu ?
If so, then I suppose I need to get the index of the menu item for "Paste."  Am I on the right track?

If this is not possible, then I will just make a popup menu and go that route, but since there already is one, I thought I would try and make use of it.

jamie

  • Hero Member
  • *****
  • Posts: 6787
Re: Popup Menu already exists?
« Reply #1 on: September 15, 2023, 02:48:30 am »
a memo normally has the system context memo but you can override that by providing your own popup.

The only true wisdom is knowing you know nothing

indydev

  • Full Member
  • ***
  • Posts: 118
Re: Popup Menu already exists?
« Reply #2 on: September 15, 2023, 04:26:26 am »
Since there doesn't seem to be a way to capture when a menu item has been chosen (I need to know if a paste event occurred using the menu), I'll just make my own menu with items.  Thought I found something quick.

jamie

  • Hero Member
  • *****
  • Posts: 6787
Re: Popup Menu already exists?
« Reply #3 on: September 16, 2023, 12:33:24 am »
Study this for a bit, put the small snippet of code in there and see how you can capture the paste interactions.

This works in windows, I can't say that in other targets.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,Lmessages;
  9.  
  10. type
  11.   TMemo = Class(stdCtrls.Tmemo)
  12.     Procedure WndProc(Var Msg:TLMessage); Override;
  13.  
  14.   end;
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     Memo1: TMemo;
  20.   private
  21.  
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32. Procedure TMemo.WndProc(Var Msg:TLMessage);
  33. Begin
  34.    If Msg.msg = LM_PASTE Then Beep;
  35.    Inherited;
  36. end;
  37.  
  38. end.
  39.  
  40.  
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018