Code
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{继承 TForm1 的类: TMyForm}
TMyForm = class(TForm1)
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1; //声明 TForm1 的实例
MyForm1: TMyForm; //声明 TMyForm 的实例
implementation
{$R *.dfm}
//Form1 上有两个按钮, Button1: 弹出信息; Button2: 创建并显示 MyForm1
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('TForm1');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
MyForm1 := TMyForm.Create(nil);
MyForm1.Show;
end;
{ TMyForm }
//TMyForm1 被创建后, 应该和 TForm1 一摸一样;
//Button2: 会继续创建并弹出新的 TMyForm1
//Button1: 会弹出两条信息, 因为继承了一条
procedure TMyForm.Button1Click(Sender: TObject);
begin
inherited; //继承 Button1 原有的功能
ShowMessage('TMyForm');
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{继承 TForm1 的类: TMyForm}
TMyForm = class(TForm1)
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1; //声明 TForm1 的实例
MyForm1: TMyForm; //声明 TMyForm 的实例
implementation
{$R *.dfm}
//Form1 上有两个按钮, Button1: 弹出信息; Button2: 创建并显示 MyForm1
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('TForm1');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
MyForm1 := TMyForm.Create(nil);
MyForm1.Show;
end;
{ TMyForm }
//TMyForm1 被创建后, 应该和 TForm1 一摸一样;
//Button2: 会继续创建并弹出新的 TMyForm1
//Button1: 会弹出两条信息, 因为继承了一条
procedure TMyForm.Button1Click(Sender: TObject);
begin
inherited; //继承 Button1 原有的功能
ShowMessage('TMyForm');
end;
end.