我想在TMemo控件加入一个功能,
功能描述:是当按'Ctrl+A'时,则选中全部内容。但我不想另外加一个控件。
希望直接修改delphi基本控件的源码。
(沿用Standra面板里的那个控件)问:
1,能否修改delphi的基本控件?
2,要实现‘功能描述’应该怎个操作?

解决方案 »

  1.   

    type
      TMyMemo = class(TMemo)
      private
      published
    //实现你的功能
      end;  TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        memo1: TMyMemo;
      public
        { Public declarations }
      end;
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      memo1 := TMyMemo.Create(self);
      Memo1.parent := self;
      Memo1.top := .....
    end;
      

  2.   

    TMyMemo=Class(TMemo)
      private
        procedure OnKeyPress(var Msg: TWMKEYDOWN);message WM_KEYDOWN;
      end;procedure TMyMemo.OnKeyPress(var Msg: TWMKEYDOWN);
    var
      str: String;
    begin
      if (Msg.CharCode=65) and (Msg.KeyData=1966081) then
      begin
        Msg.Result:=1;
        SelectAll;
      end
    end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TMyMemo=Class(TMemo)
      private
        procedure OnKeyPress(var Msg: TWMKEYDOWN);message WM_KEYDOWN;
      end;  TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FMemo: TMyMemo;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      FMemo:=TMyMemo.Create(self);
      FMemo.Parent:=Self;  FMemo.Left:=20;
      FMemo.Top:=20;
      FMemo.Width:=Width -40;
      FMemo.Height:=Height-70;
      FMemo.ScrollBars:=ssBoth;
    end;{ TMyMemo }procedure TMyMemo.OnKeyPress(var Msg: TWMKEYDOWN);
    var
      str: String;
    begin
      if (Msg.CharCode=65) and (Msg.KeyData=1966081) then
      begin
        Msg.Result:=1;
        SelectAll;
      end
    end;end.
      

  4.   

    简单:
    在memo的keydown或keyup事件写:
    if (ssctrl in shift) and(key in [65,97]) then memo1.SelectAll;
    就ok了
    如果不行在form的keydown或keyup事件也加上这句话
      

  5.   

    inherited from vcl or clx libarary is delphi's very good qualities to vb
    you can point new on toolbar then point new commponent.
    then you can create your tselectallmemo control.
    other like up  aliezeng77(钝刀)
      

  6.   

    Sorry! 条件写错了,更正如下procedure TMyMemo.OnKeyDown(var Msg: TWMKEYDOWN);
    begin
      if (GetKeyState(VK_CONTROL)<0) and (Msg.CharCode=65) then
      begin
        SelectAll;
        Msg.Result:=0;
      end;
    end;end.
      

  7.   

    要不要试试修改StdCtrls单元的
    procedure TCustomMemo.KeyPress(var Key: Char);
    原代码如下:
    procedure TCustomMemo.KeyPress(var Key: Char);
    begin
      inherited KeyPress(Key);
      if (Key = Char(VK_RETURN)) and not FWantReturns then Key := #0;
    end;
    再加入一行,变成:
    procedure TCustomMemo.KeyPress(var Key: Char);
    begin
      inherited KeyPress(Key);
      if (Key = Char(VK_RETURN)) and not FWantReturns then Key := #0;
      if (Key = Char(1)) then SelectAll;
    end;
    再想办法把它重新安装到组件面板...
      

  8.   

    首先,非常感谢大家的意见
    但请大家看详细一点我的描述。
    与我所要的结果所类似就是 Jexhat(真有你的) 所说的那种。to Jexhat(真有你的)
      你说到: "... 再想办法把它重新安装到组件面板..."1,怎个办法把它重新安装到组件面板?
    2,StdCtrls是那个包的?
      

  9.   

    做新的控件,一定不要修改VCL源码面向对象的基本思想就是对修改关闭,对扩展打开
    你可以扩展它还为什么要修改它呢
      

  10.   

    因为Ctrl+A实在太常用了。我不想仅仅为了加个Ctrl+A功能就在每个程序里加个bpl(或一段代码)
    或额外的加多一个面板图标。
      

  11.   

    Delphi6.0里dclstd60.bpl装的就是Standard组件。
    (StdCtrls.pas里没有procedure Register;)
    我没有做过bpl包, 不会啊.
      

  12.   

    用RichEdit就行,RichEdit本身支持Ctrl+A