Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 是否自动允许Ctrl+A在TMemo中选择全部?_Delphi_Keyboard Shortcuts_Delphi 7_Tmemo - Fatal编程技术网

Delphi 是否自动允许Ctrl+A在TMemo中选择全部?

Delphi 是否自动允许Ctrl+A在TMemo中选择全部?,delphi,keyboard-shortcuts,delphi-7,tmemo,Delphi,Keyboard Shortcuts,Delphi 7,Tmemo,在Delphi7的TMemo控件中,尝试按组合键Ctrl+A选择全部不会执行任何操作也不会选择全部。所以我做了这个程序: procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var C: String; begin if ssCtrl in Shift then begin C:= LowerCase(Char(Key)); if C = 'a' then

在Delphi7的TMemo控件中,尝试按组合键Ctrl+A选择全部不会执行任何操作也不会选择全部。所以我做了这个程序:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  C: String;
begin
  if ssCtrl in Shift then begin
    C:= LowerCase(Char(Key));
    if C = 'a' then begin
      Memo1.SelectAll;
    end;
  end;
end;
有没有什么窍门可以让我不用做这个手术?如果没有,那么这个过程看起来正常吗?

这更优雅:

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = ^A then
  begin
    (Sender as TMemo).SelectAll;
    Key := #0;
  end;
end;

我使用前面的回答和讨论创建了一个独立组件,用于处理我在小型测试程序中使用的按键事件

TSelectMemo = class(TMemo)
protected
  procedure KeyPress(var Key: Char); override;
end;


向窗体上的所有组件添加“全选”行为的另一种方法是使用标准的“全选”操作向窗体添加操作列表

就我个人而言,我宁愿创建一个从标准备忘录派生的组件,并在其中处理按键,这样您就不需要用特殊的处理代码污染所有表单。@David:您知道多行模式下的标准Windows编辑控件是否不允许Ctrl+a命令,或者VCL包装器是否有问题吗?TEdit可以像人们期望的那样处理Ctrl+A。@Andreas一旦我可以使用编译器访问机器,我将尝试生成一个原始的win32 petzold程序并进行检查。这似乎是一个没有文档说明的操作系统问题。很多关于它的帖子都是基于你自己的代码。@David:如果我没弄错的话,Raymond会时不时地向他的读者询问一些要写的东西。这将是一个有趣的话题。我知道我会讲一点,但你能不能为我这样的外行解释一下^a!Ctrl+A击键作为一个字符发送,顺序值为1 Ctrl+B为2,Ctrl+C为3,以此类推。。基本上,我认为这是从旧时代遗留下来的。这些“字符”通常写为^A、^B等,Delphi支持这些字符。你可以在ASCII表格中看到它们,比如。多年没看到了,一定是从TP天开始的。@Jerry:结果不完全一样。您的代码无法处理恼人的“嘟嘟”声@杰瑞:哎呀,这没办法。这是windows编辑控件的默认行为,您可以了解编辑控件的预期行为。
procedure TSelectMemo.KeyPress(var Key: Char);
begin
  inherited;
  if Key = ^A then
    SelectAll;
end;