?
Solved

Disable Cut command

Posted on 1998-08-08
5
Medium Priority
?
576 Views
Last Modified: 2010-04-04

How can i disable Cut, Copy, and Paste comands with delphi?

Codes... please
0
Comment
Question by:dia050398
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361737
Hi dia,

 Why do you want to do this?

but here is the way :

you make a new descendant of TEdit, and check the windows messages WM_PASTE, WM_CUT AND WM_COPY. In these methods, you DON'T call the inherited method.

Zif.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 280 total points
ID: 1361738
this is probably a way through the Form methods :

This is an example for COPY. Do the same for cut and paste. write the following:

   procedure TForm1.FormCreate(Sender: TObject);
   begin
     Application.OnMessage := AppMessage;
   end;

   procedure TForm1.AppMessage(var Msg: TMsg; var              Handled: Boolean);
    begin
     if (Msg.hwnd = edit1.Handle) and //if the focus is in the edit1
      (Msg.Message=WM_KEYDOWN) and //if the user              pressed a key
       ((Msg.wParam = 67) OR (Msg.wParam = 99)) then //if C or c was pressed
       begin
        if GetKeyState(VK_CONTROL) < 0 then //if control        key is down
         showmessage('copy is canceled');
         Handled := True;//cancel the copy action
       end;

Possible the same for WM_PASTE, .... but I didn't tried it.

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361739
Last sentence had to be :

 same for PASTE and CUT.

You probebly also can get the same with WM_PASTE, WM_COPY, WM_CUT but I don't think they are available at form level, so this need to be done in a descendant of TEdit, ...

Zif.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1361740
Hi,
Here's a simple implementation I wrote for this question. It's probably missing some minor details but it works. It adds a default popupmenu [undo|delete|select all] and removes all clipboard messages. There might be some tricks in here that can be useful to you:

unit NoCBEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Menus;

type
  TNoClipBoardEdit = class( TCustomEdit )
  private
    FDefaultMenu: TPopupMenu;
    FUndo, FDelete, FSelectAll : TMenuItem;
    procedure WndProc( var Message: TMessage ); override;
    procedure SetPopup( Menu: TPopupMenu );
    function  GetPopup: TPopupMenu;
    { Private declarations }
  protected
    procedure ContextDelete   ( Sender: TObject );
    procedure ContextUndo     ( Sender: TObject );
    procedure ContextSelectAll( Sender: TObject );
    procedure OnDefaultPopup  ( Sender: TObject );

    { Protected declarations }
  public
    constructor Create( AOwner: TComponent ); override;
    { Public declarations }
  published
    property PopupMenu: TPopupMenu read GetPopup write SetPopup;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents( 'Samples', [ TNoClipBoardEdit ] );
end;

constructor TNoClipBoardEdit.Create( AOwner: TComponent );
var
  mi1, mi2, mi3, sp1, sp2: TMenuItem;
begin
  inherited Create( AOwner );
  FDefaultMenu := TPopupMenu.Create( Self );
  with FDefaultMenu do begin
    OnPopup := OnDefaultPopup;
    sp1 := TMenuItem.Create( Self ); sp1.Caption := '-';
    sp2 := TMenuItem.Create( Self ); sp2.Caption := '-';
    FUndo      := TMenuItem.Create( Self ); FUndo.Caption := '&Undo';            FUndo.OnClick := ContextUndo;
    FDelete    := TMenuItem.Create( Self ); FDelete.Caption := '&Delete';        FDelete.OnClick := ContextDelete;
    FSelectAll := TMenuItem.Create( Self ); FSelectAll.Caption := 'Select &All'; FSelectAll.OnClick := ContextSelectAll;
    Items.Add( FUndo ); Items.Add( sp1 ); Items.Add( FDelete ); Items.Add( sp2 ); Items.Add( FSelectAll );
  end;
end;

procedure TNoClipBoardEdit.WndProc( var Message: TMessage );
begin
  case Message.Msg of
    WM_COPY, WM_PASTE, WM_CUT:; // do nothing!
    WM_CONTEXTMENU: if Assigned( PopupMenu )
      then PopupMenu.Popup( LOWORD( Message.LParam ), HIWORD( Message.LParam ) )
      else FDefaultMenu.Popup( LOWORD( Message.LParam ), HIWORD( Message.LParam ) );
    else inherited WndProc( Message );
  end;
end;

procedure TNoClipBoardEdit.ContextDelete   ( Sender: TObject );
begin
  SendMessage( Handle, WM_CLEAR, 0, 0 );
end;

procedure TNoClipBoardEdit.ContextUndo     ( Sender: TObject );
begin
  SendMessage( Handle, WM_UNDO, 0, 0 );
end;

procedure TNoClipBoardEdit.ContextSelectAll( Sender: TObject );
begin
  SendMessage( Handle, EM_SETSEL, 0, -1 );
end;

procedure TNoClipBoardEdit.OnDefaultPopup  ( Sender: TObject );
begin
  FUndo.Enabled      := Boolean( SendMessage( Handle, EM_CANUNDO, 0, 0 ) );
  FDelete.Enabled    := SelLength > 0;
  FSelectAll.Enabled := SelLength < Length( Text );
end;

procedure TNoClipBoardEdit.SetPopup( Menu: TPopupMenu );
begin
  if Assigned( Menu )
  then inherited PopupMenu := Menu
  else inherited PopupMenu := FDefaultMenu;
end;

function  TNoClipBoardEdit.GetPopup: TPopupMenu;
begin
  Result := inherited PopupMenu;
end;

end.

Use it a a "normal" TEdit.

/// John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1361741
Sorry!
The SetPopup event is erroneous. Remove the else statement.
You could remove the PopupMenu property completely and use the inherihed.

/// John
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question