各位以下为我的初步考虑,结果出错,请指教,(原问题提出者)
unit EnterToTab;
interface
uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
Forms, Graphics, Dialogs;
type
TEnterToTab = class(TComponent)
private
FActive : Boolean; //打算用于设置启动关闭的开关
procedure AutoInitialize;
procedure AutoDestroy;
Procedure NewKeyPress(Sender: TObject; var Key: Char);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Active : Boolean read FActive write FActive;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TEnterToTab]);
end;
procedure TEnterToTab.AutoInitialize;
begin
end; { of AutoInitialize }
procedure TEnterToTab.AutoDestroy;
begin
{ No objects from AutoInitialize to free }
end; { of AutoDestroy }
constructor TEnterToTab.Create(AOwner: TComponent);
Var
MYForm: TCustomForm;
begin
inherited Create(AOwner);
AutoInitialize;
MYForm := GetParentForm(AOwner); //通过自己获取父类Form
MYForm.KeyPreview:=True; //设置父类KeyPreview
MYForm.OnKeyPress:=NewKeyPress; //设置父类OnKeyPress---出错
end;
Procedure TEnterToTab.NewKeyPress(Sender: TObject; var Key: Char);
Begin
//只想检测是否成功截取和设置OnKeyPress
//新的OnKeyPress处理程序
if Key = #13 then ShowMessage('Everything Is OK!');
then inherited KeyPress(Key); }
End;
destructor TEnterToTab.Destroy;
begin
AutoDestroy;
inherited Destroy;
end;
end.