Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to disable the select and copy to clipboard capabilities in a TMemo Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
116
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to disable the select and copy to clipboard capabilities in a TMemo

Answer:

Solve 1:

Use OnKeyDown and OnKeyPress handlers for the memo to catch the shortcuts for copy 
and cut and set key := 0 for them. Provide a handler for the OnContextMenu event in 
which you set Handled to true to prevent the default popup menu from coming up. 
That should do it.
1   
2   procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
3   begin
4     if ssCtrl in Shift then
5       case Key of
6         Ord('C'), Ord('X'), VK_INSERT: Key := 0;
7       end
8     else if (ssShift in Shift) and (Key = VK_DELETE) then
9       Key := 0;
10  end;
11  
12  procedure TForm1.Memo1ContextPopup(Sender: TObject; MousePos: TPoint;
13    var Handled: Boolean);
14  begin
15    Handled := true;
16  end;
17  
18  procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
19  begin
20    if Key in [^C, ^X] then
21      Key := #0;
22  end;



Solve 2:

The easiest way would be to set the Enabled property of the Memo (or Edit) control 
to False so that the control cannot receive events. This drawback to this method is 
the user won't be able to scroll the text and the disabled text looks bad. 

In order to prevent the user from writing in the memo, we set its ReadOnly property 
to True. 

To prevent the user from selecting text with the mouse, we generate the handler of 
the MouseMove event of the control and write the following code: 

23  procedure TForm1.Memo1MouseMove(Sender: TObject;
24    Shift: TShiftState; X, Y: Integer);
25  begin
26    if ssLeft in Shift then
27      Memo1.SelLength := 0;
28  end;


In order to prevent the user from performing a selection using the keyboard, we 
generate the handlers of the KeyDown and KeyUp events, assigning the OnKeyDown and 
OnKeyUp properties to the same procedure: 
29  
30  procedure TForm1.Memo1KeyDownUp(Sender: TObject;
31    var Key: Word; Shift: TShiftState);
32  begin
33    if (ssShift in Shift) and (Key in [VK_LEFT, VK_RIGHT, VK_UP,
34      VK_DOWN, VK_PRIOR, VK_NEXT, VK_HOME, VK_END]) then
35      Key := 0;
36  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC