我使用的是 TDBMemo
控件。我想防止用户在粘贴时使用 CTRL+V.
这个办法行不通。
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;
所以,我试了别的办法
if (Key=#86) then Key := #0; // this is ok, doesnt allow letter v.
但是当我尝试的时候:
if (Key=#17) AND (Key=#86) then Key := #0; // #17 is supposed to be CTRL value...
它不工作。
如果我的理解是正确的,请把这个放在你的使用TDBMemo的单元的顶部
type
TDBMemo = Class(DBCtrls.TDbMemo)
procedure WMPaste(var Message: TMessage); message WM_PASTE;
end;
然后,在执行部分
procedure TDBMemo.WMPaste(var Message: TMessage);
begin
// do nothing
end;
[tbc]如果你想在包含TDBMemos的多个单元中实现这一行为,请将上述代码放入一个单独的单元中,然后确保它出现在任何其他包含TDBMemo的单元的Uses列表中。之后 DBCtrls,这样就会在所有涉及的单位中生效。