Volkan
Volkan

Reputation: 546

Prevent CTRL-V in TDBMemo

I am using a TDBMemo control in Delphi 7. I would like to prevent the user from pasting in it with CTRL+V.

This solution doesn't work:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#22) or (Key=#3) then Key:=#0;   // 22 = [Ctrl+V] / 3 = [Ctrl+C]
end;

So, I tried something else:

if (Key=#86) then Key := #0; // this is ok, doesnt allow letter v.

But when I try:

if (Key=#17) AND (Key=#86) then Key := #0; // #17 is supposed to be CTRL value...

it doesnt work.

Upvotes: 0

Views: 638

Answers (1)

MartynA
MartynA

Reputation: 30735

If I am understamding what you want correctly, put this at the top of your unit that uses TDBMemo

type

  TDBMemo = Class(DBCtrls.TDbMemo)
    procedure WMPaste(var Message: TMessage); message WM_PASTE;
  end;

Then, in the implementation section

procedure TDBMemo.WMPaste(var Message: TMessage);
begin
  // do nothing
end;

[tbc]If you want this behaviour in more than one unit which includes TDBMemos, put the code above into a separate unit, then make sure that it appears in the Uses list of any other TDBMemo-containing unit after DBCtrls, that way it will take effect in all the units involved.

Upvotes: 4

Related Questions