Author Topic: Disabling the system's right-click pop-up menu in a TEdit  (Read 648 times)

atlatl

  • New Member
  • *
  • Posts: 31
Disabling the system's right-click pop-up menu in a TEdit
« on: October 11, 2026, 06:29:16 pm »
I would like to disable Apple's contextual menu in a TEdit, but try as I might, I can't seem to
This:
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint; VAR Handled: Boolean);
  2.   BEGIN
  3.     Handled := True;
  4.   END;
  5.  
should(?) do it, but no luck. Has anyone got any other ideas?

Thanks, Harv

Bart

  • Hero Member
  • *****
  • Posts: 5800
    • Bart en Mariska's Webstek
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #1 on: October 11, 2026, 06:30:19 pm »
Assign an empty TPopupMenu to the edit?

Bart

zeljko

  • Hero Member
  • *****
  • Posts: 2038
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #2 on: October 11, 2026, 06:32:08 pm »
I would like to disable Apple's contextual menu in a TEdit, but try as I might, I can't seem to
This:
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint; VAR Handled: Boolean);
  2.   BEGIN
  3.     Handled := True;
  4.   END;
  5.  
should(?) do it, but no luck. Has anyone got any other ideas?

Thanks, Harv

Open an issue against cocoa widgetset ?

n7800

  • Hero Member
  • *****
  • Posts: 811
  • Lazarus IDE contributor
    • GitLab profile
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #3 on: October 11, 2026, 10:13:42 pm »
Has anyone got any other ideas?

Please specify the version of Lazarus you are using so that someone can verify whether the error still exists.

If you are certain it is a bug, then, as mentioned, report it on the bug tracker.

n7800

  • Hero Member
  • *****
  • Posts: 811
  • Lazarus IDE contributor
    • GitLab profile
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #4 on: October 11, 2026, 10:14:59 pm »
Assign an empty TPopupMenu to the edit?

At least on Windows, setting it to "Handled:=true" is sufficient.

atlatl

  • New Member
  • *
  • Posts: 31
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #5 on: October 12, 2026, 01:23:50 am »
Thanks for the responses.

@Bart: Sadly, that didn't help. The system's menu still pops up.

@zeljko: Yes, that's a good idea.

@n7800: Well, It's what fpcupdeluxe calls Lazarus 4.9 revision aaba428c01...
So, I'm guessing it's some version of 4.8(?).

Thanks again, Harv

DomingoGP

  • Full Member
  • ***
  • Posts: 126
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #6 on: October 12, 2026, 09:56:48 am »
One option that works on all widgetsets is to derive a new control and process the LM_CONTEXTMENU message like this code sample.

Code: Pascal  [Select][+][-]
  1. unit MyEdit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. //{$R 'myedit.res'}
  8.  
  9. uses
  10.   Classes, SysUtils, Graphics, Math, StrUtils,
  11.   LCLType, LCLProc, lmessages, Controls, StdCtrls, Forms;
  12.  
  13. type
  14.   TMyEdit = class(TEdit)
  15.   protected
  16.     procedure LMContextMenu(var Message: TLMessage); message LM_CONTEXTMENU;
  17.   end;
  18.  
  19. implementation
  20.  
  21. procedure TMyEdit.LMContextMenu(var Message: TLMessage);
  22. begin
  23.   //AVOID SHOWING CONTEXT MENU. WORKS ON ALL WIDGETSETS.
  24.   Message.Result := 1;
  25. end;
  26.  
  27. //procedure Register;
  28. //begin
  29. //  RegisterComponents('myComponents', [TMyEdit]);
  30. //end;
  31.  
  32. end.
  33.  

Note: I really not tested this code on cocoa, but is part of the attached control to edit currency that don't allow paste that works on windows, cocoa, qt5, qt6, gtk2 and gtk3.



atlatl

  • New Member
  • *
  • Posts: 31
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #7 on: October 12, 2026, 07:02:03 pm »
Hi DomingoGP.

I tried using your MyEdit unit in a minimal app:
Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. INTERFACE
  6.  
  7. USES
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, MyEdit;
  9.  
  10. TYPE
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = CLASS(TForm)
  15.     MyEdit1: TMyedit;
  16.     PROCEDURE FormCreate(Sender: TObject);
  17.   PRIVATE
  18.  
  19.   PUBLIC
  20.  
  21.   END;
  22.  
  23. VAR
  24.   Form1: TForm1;
  25.  
  26. IMPLEMENTATION
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. PROCEDURE TForm1.FormCreate(Sender: TObject);
  33.   BEGIN
  34.     MyEdit1 := TMyEdit.Create(Self);
  35.     MyEdit1.Parent := Form1;
  36.     MyEdit1.Top := 10;
  37.     MyEdit1.Left := 10;
  38.     MyEdit1.Visible := True;
  39.   END;
  40. END.
  41.  

Unfortunately, the OS's contextual menu popped up. However, this may be due to the way I included your code.(?)

Thanks for your help, Harv

DomingoGP

  • Full Member
  • ***
  • Posts: 126
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #8 on: October 12, 2026, 07:45:35 pm »
Quote
Unfortunately, the OS's contextual menu popped up. However, this may be due to the way I included your code.(?)

I'm sorry, Your are right the code only was tested in an old version of lazarus (lazarus version 2.1.0) on one Mojave VM and worked well.

When I tested the same code with a more actual version of lazarus (4.99) it pops up :(.

n7800

  • Hero Member
  • *****
  • Posts: 811
  • Lazarus IDE contributor
    • GitLab profile
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #9 on: October 14, 2026, 10:01:26 am »
@n7800: Well, It's what fpcupdeluxe calls Lazarus 4.9 revision aaba428c01...
So, I'm guessing it's some version of 4.8(?).

Will you create a report in the bug tracker? Let me know if you need any help.

atlatl

  • New Member
  • *
  • Posts: 31
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #10 on: October 15, 2026, 02:31:46 pm »
Thanks for the offer, n7800.

I may, at some point, file a report. But, for now, i'm going to try find a workaround for my issue.

mas steindorff

  • Hero Member
  • *****
  • Posts: 615
Re: Disabling the system's right-click pop-up menu in a TEdit
« Reply #11 on: October 15, 2026, 06:40:19 pm »
Hi DomingoGP.

I tried using your MyEdit unit in a minimal app:
Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. INTERFACE
  6.  
  7. USES
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, MyEdit;
  9.  
  10. TYPE
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = CLASS(TForm)
  15.     MyEdit1: TMyedit;
  16.     PROCEDURE FormCreate(Sender: TObject);
  17.   PRIVATE
  18.  
  19.   PUBLIC
  20.  
  21.   END;
  22.  
  23. VAR
  24.   Form1: TForm1;
  25.  
  26. IMPLEMENTATION
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. PROCEDURE TForm1.FormCreate(Sender: TObject);
  33.   BEGIN
  34.     MyEdit1 := TMyEdit.Create(Self);
  35.     MyEdit1.Parent := Form1;
  36.     MyEdit1.Top := 10;
  37.     MyEdit1.Left := 10;
  38.     MyEdit1.Visible := True;
  39.   END;
  40. END.
  41.  

Unfortunately, the OS's contextual menu popped up. However, this may be due to the way I included your code.(?)

just verifying, this code does not set any of the  TEdit's OnMouse events so they are still progressed by the default handler.
for this code, you need something like
Code: [Select]
Myedit1.OnMouseDown = @TForm1.Edit1ContextPopup(...)
since you are not using the object inspector.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

 

TinyPortal © 2005-2018