[SOLVED] Problem with popupmenu lazarus / 31-LCL ---------------------------------------------------------------------- madepabloh · 2012-06-11 13:59 HI folks, In my application i have some componentes such as  a memo and a LabeledEdit. I didn´t create a popupmenu for my application. However, when i do click (right button of the mouse) a popupmenu appear on my application. I want to leave those componentes enabled, but without any kind of popupmenu... What i miss to adjust in the characteristics of those components? Thanks! ---------------------------------------------------------------------- KpjComp · 2012-06-11 14:08 On the OnContextPopup event just set Handled := true; eg. Code: [Select]procedure TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint;   var Handled: Boolean); begin   Handled := true; end; ---------------------------------------------------------------------- madepabloh · 2012-06-12 07:42 Thanks KpjComp, It works perfectly for the TMemo component... However, the "OnContextPopup" event does not exist on the LabeledEdit component... ---------------------------------------------------------------------- Bart · 2012-06-12 07:58 Create an empy popupmenu and attach it to the control? (= Untested advice) Bart ---------------------------------------------------------------------- KpjComp · 2012-06-12 08:57 QuoteHowever, the "OnContextPopup" event does not exist on the LabeledEdit component... On ContextPopupUp is defined in TControl, but it's not been published in TLabeledEdit, so one way is to create what's called a cracker class. First define the cracker class in the same unit you want to expose protected methods/events. Code: [Select]type   TControlCrack = class(TControl)   end; now we can use our cracker class to access protected members. Code: [Select]  TControlCrack(LabeledEdit1).OnContextPopup:=@Edit1ContextPopup;   Another way is you could create your own TLabeledEdit that just exposes the OnContextPopup. eg. Code: [Select]type   TMyLabledEdit = class(TLabeledEdit)   published     property OnContextPopup;   end;    You could even then register this custom component and have it appear at design time. Or alternatively just create the component in code. eg. Code: [Select]  with TMyLabledEdit.Create(self) do begin     OnContextPopup := @Edit1Contextpopup;     parent := self;     //left,top etc..   end; ---------------------------------------------------------------------- madepabloh · 2012-06-12 09:55 OMG, i know whay i am still a Junior member...  I think that the most shorter and easy for a newby is your first proposal... i will try it and see if i could resolve the problem in that way. Thanks! ---------------------------------------------------------------------- KpjComp · 2012-06-12 10:46 To make it easer I've created a simple unit. Code: [Select] unit uNullContextPopup; {$mode objfpc}{$H+} interface uses   Classes,controls, SysUtils; procedure NullContextPopup(Sender:TControl); implementation type   TControlCrack = class(TControl)   end;   TDummyObject = class     procedure NullPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);   end; var   DummyObject:TDummyObject; procedure TDummyObject.NullPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean); begin   Handled := true; end; procedure NullContextPopup(Sender:TControl); begin   TControlCrack(Sender).OnContextPopup:=@DummyObject.NullPopup; end; initialization   dummyObject:=TDummyObject.Create; finalization   freeAndNil(dummyObject); end. Save the above as unullcontextpopup.pas, and put in your uses clause. You can now do. Code: [Select]  NullContextPopup(LabeledEdit1); ---------------------------------------------------------------------- KpjComp · 2012-06-12 10:56 Another idea!!,.. If you have lots of controls on a form that have ContextPopups, rather than doing -> Code: [Select]NullContextPopup(edit1); NullContextPopup(edit2); //etc You can iterate them automatically. I've add a NullAllContextPopups function, you can then simply put this on your FormCreate -> Code: [Select]  NullAllContextPopups(self); Here's the revised unit. Code: [Select]unit uNullContextPopup; {$mode objfpc}{$H+} interface uses   Classes,controls, SysUtils; procedure NullContextPopup(Sender:TControl); procedure NullAllContextPopups(Sender:TWinControl); implementation type   TControlCrack = class(TControl)   end;   TDummyObject = class     procedure NullPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);   end; var   DummyObject:TDummyObject; procedure TDummyObject.NullPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean); begin   Handled := true; end; procedure NullContextPopup(Sender:TControl); begin   TControlCrack(Sender).OnContextPopup:=@DummyObject.NullPopup; end; procedure NullAllContextPopups(Sender:TWinControl); //   procedure DoIt(w:TWinControl);   var     l:integer;     c:TControl;   begin     for l := 0 to w.ControlCount-1 do     begin       c := w.Controls[l];       NullContextPopup(c);       if c is TWinControl then DoIt(TWinControl(c));     end;   end; // begin   DoIt(Sender); end; initialization   dummyObject:=TDummyObject.Create; finalization   freeAndNil(dummyObject); end. ---------------------------------------------------------------------- madepabloh · 2012-06-12 11:04 You are my HERO (yes, with capital letters!) Thanks so much! It works perfect!!! You solved the problem perfecty. Thanks so much for do this programming work for me. By the way, i think that the unit you created will be useful to many other people. So thanks for your help and efforts. I really appreciate it! ---------------------------------------------------------------------- KpjComp · 2012-06-12 11:29 No Problem.  One of the things I've always liked about been a pascal programmer is how so many other pascal programmers are happy to help each other.   I remember the days when I first used Delphi 1, and the community spirit was the best.  The same spirit applies here too,  @lulub / @Bart / @Bigchimp and many many more are always happy to help.  "The Spirit of Delphi lives on in Lazarus/FPC" ---------------------------------------------------------------------- madepabloh · 2012-06-12 11:51 Yes. I know what you mean... i started with Delphi 3 a lot of years ago... (when i was young and had something of free time) and i knew its forum... I agree that there are a lot of people in the Lazarus forum what are really great and help a lot to the novices such as myself.  Thanks to all of you folks!