Author: Tomas Rutkauskas
I have several TDBEdits on a groupbox which is on a TabControl. The TabControl has
its own PopupMenu and the DBEdits are assuming this menu, even though I only want
the DBEdits to have the standard Windows Edit/ Cut/ Paste. How do I stop the
DBEdit's from assuming the TabControls PopUp? Their PopUpMenu property is not set
to anything.
Answer:
That turned out to be a pretty hairy problem. I was able to solve it but the
solution ain't pretty. Attach a common handler to all the edits OnContextMenu
event. Modify the form as follows:
1 { ... }2 private3 { Private declarations }4 5 procedure wmUser(var msg: TMessage); message wm_user;
6 public7 { Public declarations }8 end;
9 10 var11 Form1: TForm1;
12 13 implementation14 15 {$R *.DFM}16 17 type18 twc = class(twincontrol)
19 public20 property DefWndProc;
21 end;
22 23 procedure TForm1.wmUser(var msg: TMessage);
24 begin25 with twc(msg.wparam) do26 callwindowproc(defwndproc, handle, wm_contextmenu, handle, msg.lparam);
27 end;
28 29 procedure TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled:
30 Boolean);
31 begin32 handled := true;
33 postmessage(handle, wm_user, wparam(Sender),
34 lparam(PointToSmallpoint((Sender as Tedit).ClientToScreen(mousepos))));
35 end;
What this does is jumping through hoops to get the WM_CONTEXTMENU message that triggers the menu past the default message handling code in the VCL. Tested with normal TEdits, D5.01, on Win95B.