unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TMyPanel =
class(TPanel)
procedure OnMyKeyPress(Sender: TObject;
var Key: Char);
public
property OnKeyPress;
constructor Create(AOwner: TComponent);
override;
end;
TForm2 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
FPanel: TMyPanel;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TMyPanel }
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
OnKeyPress := OnMyKeyPress;
end;
procedure TMyPanel.OnMyKeyPress(Sender: TObject;
var Key: Char);
begin
ShowMessage('
');
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
FPanel:= TMyPanel.Create(Self);
FPanel.Parent:= Self;
FPanel.
Name:= '
MyPanel1';
FPanel.Align := alClient;
FPanel.Caption := '
Test';
end;
procedure TForm2.FormShow(Sender: TObject);
begin
FPanel.SetFocus;
end;
end.